本文介绍了检测霍夫圈的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测采用了android圈。我成功地实现了检测线的算法,但没有试图绘制霍夫圈algoritm时被显示出来。
这是我的code:
垫thresholdImage =新材料(getFrameHeight()+ getFrameHeight()/ 2,getFrameWidth(),CvType.CV_8UC1);
mYuv.put(0,0,数据);
Imgproc.cvtColor(mYuv,目的地,Imgproc.COLOR_YUV420sp2RGB,4);
Imgproc.cvtColor(目的地,thresholdImage,Imgproc.COLOR_RGB2GRAY,4);
Imgproc.GaussianBlur(thresholdImage,thresholdImage,新尺寸(9,9),2,2);
垫圈=新垫();
Imgproc.HoughCircles(thresholdImage,圆,Imgproc.CV_HOUGH_GRADIENT,1D,(双)thresholdImage.height()/ 70,200D,100D);
Log.w(圈子,circles.cols()+);
为(中间体X = 0 X - 其中; circles.cols(); X ++)
{
双vCircle [] = circles.get(0,x)的;
点中心=新的点(Math.round(vCircle [0]),Math.round(vCircle [1]));
INT半径=(int)的Math.round(vCircle [2]);
//绘制圆心
Core.circle(目的地,中心,3个,新标量(0,255,0),-1,8,0);
//绘制圆形轮廓
Core.circle(目的地,圆心,半径,新的标量(0,0,255),3,8,0);
}
解决方案
您可能会得到这个排序了,但几件事情。我会检查你的社交圈垫实际上有一定的效果;有时vCircle似乎又回来了空;尝试其他版本HoughCircles之一:
iCannyUpperThreshold = 100;
iMinRadius = 20;
iMaxRadius = 400;
iAccumulator = 300;
Imgproc.HoughCircles(thresholdImage,圆,Imgproc.CV_HOUGH_GRADIENT,
2.0,thresholdImage.rows()/ 8,iCannyUpperThreshold,iAccumulator,
iMinRadius,iMaxRadius);
如果(circles.cols()大于0)
为(中间体X = 0 X - 其中; circles.cols(); X ++)
{
双vCircle [] = circles.get(0,x)的;
如果(vCircle == NULL)
打破;
点PT =新的点(Math.round(vCircle [0]),Math.round(vCircle [1]));
INT半径=(int)的Math.round(vCircle [2]);
//绘制发现圈
Core.circle(目的地,PT,半径,新的标量(0,255,0),iLineThickness);
Core.circle(目的地,PT,3,新的标量(0,0,255),iLineThickness);
}
(我换你的code到煤矿,改名为一些东西,换回来的,我的认为的我得回去,这样它的作品...)
乙。
I am trying to detect circles using android. I succeeded to implement the detect lines algorithm but nothing gets displayed when trying the draw hough circles algoritm.
Here is my code:
Mat thresholdImage = new Mat(getFrameHeight() + getFrameHeight() / 2, getFrameWidth(), CvType.CV_8UC1);
mYuv.put(0, 0, data);
Imgproc.cvtColor(mYuv, destination, Imgproc.COLOR_YUV420sp2RGB, 4);
Imgproc.cvtColor(destination, thresholdImage, Imgproc.COLOR_RGB2GRAY, 4);
Imgproc.GaussianBlur(thresholdImage, thresholdImage, new Size(9, 9), 2, 2 );
Mat circles = new Mat();
Imgproc.HoughCircles(thresholdImage, circles, Imgproc.CV_HOUGH_GRADIENT, 1d, (double)thresholdImage.height()/70, 200d, 100d);
Log.w("circles", circles.cols()+"");
for (int x = 0; x < circles.cols(); x++)
{
double vCircle[]=circles.get(0,x);
Point center=new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
int radius = (int)Math.round(vCircle[2]);
// draw the circle center
Core.circle(destination, center, 3,new Scalar(0,255,0), -1, 8, 0 );
// draw the circle outline
Core.circle( destination, center, radius, new Scalar(0,0,255), 3, 8, 0 );
}
解决方案
You may have got this sorted by now, but a few things. I'd check your circles mat actually has some results; sometimes vCircle seems to come back null; try one of the other versions of HoughCircles:
iCannyUpperThreshold = 100;
iMinRadius = 20;
iMaxRadius = 400;
iAccumulator = 300;
Imgproc.HoughCircles(thresholdImage, circles, Imgproc.CV_HOUGH_GRADIENT,
2.0, thresholdImage.rows() / 8, iCannyUpperThreshold, iAccumulator,
iMinRadius, iMaxRadius);
if (circles.cols() > 0)
for (int x = 0; x < circles.cols(); x++)
{
double vCircle[] = circles.get(0,x);
if (vCircle == null)
break;
Point pt = new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
int radius = (int)Math.round(vCircle[2]);
// draw the found circle
Core.circle(destination, pt, radius, new Scalar(0,255,0), iLineThickness);
Core.circle(destination, pt, 3, new Scalar(0,0,255), iLineThickness);
}
(I swapped your code into mine, renamed some stuff and swapped it back, I think I've got it back so it works...)
B.
这篇关于检测霍夫圈的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!