C#中的霍夫圆,动态内存

发布于 2024-10-08 11:01:23 字数 945 浏览 5 评论 0原文

我在动态内存分配中从矩阵获取数据时遇到问题

Image image_gray = new Image("im1.jpg");
Matrix circles = new Matrix(100, 1, 3);

问题 1:由于我不知道圈数,如何定位动态内存?

Emgu.CV.CvInvoke.cvHoughCircles(image_gray, circles, HOUGH_TYPE.CV_HOUGH_GRADIENT,
    2, 100, 200, 100, 10, 500);

问题2:现在circle是带有[100 ,3]的矩阵,我怎样才能得到

point center= Round (circle[i][1], circle[i][1])

int radius= circle[i][2]; 

的for循环应该是什么样子来从矩阵获取数据并且转换应该是point和int。

我已经尝试过(不起作用/错误),

for (int i=0; i < circles.Rows; i++) 
{ Matrix entry = circles.GetRow(i);

 float x = entry[0]; 
 float y = entry[1]; 
float r = entry[2];} // NOT WORKING

因为它不是仅复制(必需)行,而是复制整个矩阵(圆圈)和 float x=......给出错误,

No overload for method 'this' takes '1' arguments

请在这方面帮助我

,抱歉


回答我的问题。请给动态内存分配和矩阵数据一些提示

I have problem in dynamic memory allocation getting data from matrix

Image image_gray = new Image("im1.jpg");
Matrix circles = new Matrix(100, 1, 3);

Question 1: How can I locate dynamic memory because I don't know the number of circles?

Emgu.CV.CvInvoke.cvHoughCircles(image_gray, circles, HOUGH_TYPE.CV_HOUGH_GRADIENT,
    2, 100, 200, 100, 10, 500);

Question 2: Now circle is matrix with [100 ,3], How can I get

point center= Round (circle[i][1], circle[i][1])

How can I get

int radius= circle[i][2]; 

what should my for loop look like to get data from matrix and casting should be point and int.

I tried already (NOT WORKING / ERROR)

for (int i=0; i < circles.Rows; i++) 
{ Matrix entry = circles.GetRow(i);

 float x = entry[0]; 
 float y = entry[1]; 
float r = entry[2];} // NOT WORKING

because instead of copying (required) only (i) row it copies whole matrix( circles) and float x=......gives errors

No overload for method 'this' takes '1' arguments

please help me in this regard

regards


sorry to answer my question. please give some hint to dynamic memory allocation and matrix data

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳男子 2024-10-15 11:01:23

文档表明它将增长矩阵以适应,但它也与这一点相矛盾,所以老实说,我会在具有更多圆圈的图像上尝试 1 行 1 列矩阵,看看它会给你带来什么。我看到您正在使用 Matrix 类型 - 我不知道如何转换为 cvHoughCircles 所需的 IntPtr,但应该直接迭代每一行并提取结果,即 3 个浮点数:(x, y、r)-

for (int i=0; i < circles.Cols; i++) {
    Matrix<float> entry = circles.GetRow(i);
    float x = entry[0]; // guessing here - the doc'n is truly awful
    float y = entry[1];
    float r = entry[2];
}

The documentation suggests that it will grow the matrix to fit, but it also contradicts that, so honestly, I would try a 1 row 1 col matrix on an image with more circles and see what it gives you. I see that you're using Matrix type - I don't know how you convert to the IntPtr needed by cvHoughCircles, but it should be straight forward to iterate over each row and pull out the results, which are 3 floats: (x, y, r) -

for (int i=0; i < circles.Cols; i++) {
    Matrix<float> entry = circles.GetRow(i);
    float x = entry[0]; // guessing here - the doc'n is truly awful
    float y = entry[1];
    float r = entry[2];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文