Opencv 为什么圆检测检测到的圆比它所在的圆多?
我使用以下函数来检测图像。但是,它检测到数千个圆圈,而不是16个。我怎样才能确保它只检测到我看到的东西?改变半径或相对强度没有任何区别。 我使用的图像如下: 请从以下位置尝试此python解决方案: 输出:Opencv 为什么圆检测检测到的圆比它所在的圆多?,opencv,Opencv,我使用以下函数来检测图像。但是,它检测到数千个圆圈,而不是16个。我怎样才能确保它只检测到我看到的东西?改变半径或相对强度没有任何区别。 我使用的图像如下: 请从以下位置尝试此python解决方案: 输出: 16这太棒了,但在我的应用程序中,我需要在C GUI中使用它。在最坏的情况下,我可以将此称为后台。希望其他人可以帮助您在C中完成此操作,因为我不是后台人员你好,Ishara,你能修改这个脚本来分割比circle稍大的圆形正方形图像,并用原始的\u name\u bump\u number格式
16这太棒了,但在我的应用程序中,我需要在C GUI中使用它。在最坏的情况下,我可以将此称为后台。希望其他人可以帮助您在C中完成此操作,因为我不是后台人员你好,Ishara,你能修改这个脚本来分割比circle稍大的圆形正方形图像,并用原始的\u name\u bump\u number格式保存到原始图像位置吗?@PCG我根据你的要求编辑了解决方案,据我所知。谢谢你Ishara。我会试试这个。此外,我还能够使用C包装器EmguCV使C工作。现在我需要检查哪一个更快。
Bitmap ImageBitmap = (Bitmap)pictureBox1.Image;
var filter = new FiltersSequence(new IFilter[]
{
Grayscale.CommonAlgorithms.BT709,
new Threshold(0x40)
});
var binaryImage = filter.Apply(ImageBitmap);
// for (int i = 0; i < 10000; i++)
{
// System.Drawing.Image image = System.Drawing.Image.FromFile(imagePath);
// GrayBMP_File.CreateGrayBitmapFile(image, "c:/path/to/8bpp/image.bmp");
// Bitmap ImageBitmap = Convert.Gra ImageBitmap.Con
HoughCircleTransformation circleTransform = new HoughCircleTransformation(50);
// apply Hough circle transform
circleTransform.ProcessImage(binaryImage);
Bitmap houghCirlceImage = circleTransform.ToBitmap();
// get circles using relative intensity
HoughCircle[] circles = circleTransform.GetCirclesByRelativeIntensity(0.9);
int numCircles = circleTransform.CirclesCount;
label1.Text = numCircles.ToString();
pictureBox1.Image = houghCirlceImage;
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(ImageBitmap);
foreach (HoughCircle circle in circles)
{
g.DrawEllipse(Pens.Green, circle.X, circle.Y, 10,10);
}
pictureBox1.Image = ImageBitmap;
// ImageBitmap.Dispose();
// binaryImage.Dispose();
}
import cv2
import numpy as np
img = cv2.imread('test.jpg',0)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint16(np.around(circles))
d=1
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
crop_img=img[i[0]-i[2]-2:i[0]+i[2]+2,i[1]-i[2]-2:i[1]+i[2]+2]
cv2.imshow('cropped circle',crop_img)
cv2.imwrite('test_%d.png'%d,crop_img)
cv2.waitKey(0)
d+=1
cv2.imshow('detected circles',cimg)
print(len(circles[0,:]))
cv2.waitKey(0)
cv2.destroyAllWindows()