如何传递和使用JavaCV-houghcirles方法的参数
我试图使用该方法的JavaCV实现,但在参数方面有一些问题。 这是我的密码:如何传递和使用JavaCV-houghcirles方法的参数,java,javacv,mat,hough-transform,Java,Javacv,Mat,Hough Transform,我试图使用该方法的JavaCV实现,但在参数方面有一些问题。 这是我的密码: Mat currentImageGray = tgtFrag.getImage().clone(); Mat detectedCircles = new Mat(); HoughCircles(currentImageGray, detectedCircles, CV_HOUGH_GRADIENT, 1, 2, 254, 25, tgtFrag.getImage().rows() / 4, 0 ); if (det
Mat currentImageGray = tgtFrag.getImage().clone();
Mat detectedCircles = new Mat();
HoughCircles(currentImageGray, detectedCircles, CV_HOUGH_GRADIENT, 1, 2, 254, 25, tgtFrag.getImage().rows() / 4, 0 );
if (detectedCircles != null && !detectedCircles.empty()) {
// TO DO:
// Print the center and the raidus of the detected circles.
}
首先,检测结果(HoughCircles的第二个参数)以Mat(detectedCircles
)的形式给出
我想处理检测到的圆
垫,然后在控制台上打印圆的中心和半径。到目前为止,我的尝试都失败了:我一直在尝试使用FloatBufferIndexer
迭代detectedCircles
,这可能是正确的方向,但我还没有成功,有人能帮忙吗
请注意以下事项:
- 我用的是JavaCV,不是openCV
- 我使用的是JavaCV HoughCircles,而不是cvHoughCircles(不过使用cvHoughCircles的解决方案也可以)
- 我使用的是JavaCV的最新版本,即1.0(2015年7月)
// Get the source Mat.
Mat myImage = tgtFrag.getImage();
IplImage currentImageGray = new IplImage(myImage);
CvMemStorage mStorage = CvMemStorage.create();
CvSeq detectedCircles = cvHoughCircles(currentImageGray, mStorage, CV_HOUGH_GRADIENT, 1, 2, 254, 25, tgtFrag.getImage().rows() / 4, 0);
if (detectedCircles != null && detectedCircles.total() > 0) {
for (int i = 0; i < detectedCircles.total(); i++) {
CvPoint3D32f curCircle = new CvPoint3D32f(cvGetSeqElem(detectedCircles, i));
int curRadius = Math.round(curCircle.z());
Point curCenter = new Point(Math.round(curCircle.x()), Math.round(curCircle.y()));
System.out.println(curCenter);
System.out.println(curRadius);
}
}
//获取源文件。
Mat myImage=tgtFrag.getImage();
IplImage currentImageGray=新IplImage(myImage);
CvMemStorage mStorage=CvMemStorage.create();
CvSeq detectedCircles=cvHoughCircles(currentImageGray,mStorage,CV_HOUGH_GRADIENT,1,2,254,25,tgtFrag.getImage().rows()/4,0);
if(detectedCircles!=null&&detectedCircles.total()>0){
对于(int i=0;i
尽管这不能直接解决您的问题,但我希望这可能会有所帮助。谢谢@tzeenth,这确实可以解决我的问题,即使很难,我希望看到使用Houghcirle方法,而不是CVHoughcirles。我将等待一段时间,然后将此标记为我问题的答案。