在 JavaCV 或 OPENCV 中查找轮廓 [英] Find contours in JavaCV or OPENCV
本文介绍了在 JavaCV 或 OPENCV 中查找轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,但我不知道是什么!我有下一个代码,当我调试它时,调试器停止在
I have a problem but I don't know what! I have the next code, and when I debug it, the debugger stops in the
IplImage iplGray = cvCreateImage(cvGetSize(iplUltima), 8, 1 );
CvMemStorage g_storage = null;
CvSeq contours = new CvSeq(iplGray);
opencv_imgproc.cvCvtColor(iplUltima, iplGray, opencv_imgproc.CV_BGR2GRAY);
opencv_imgproc.cvThreshold(iplGray, iplGray, 100, 255, opencv_imgproc.CV_THRESH_BINARY);
//HERE, the next line:
opencv_imgproc.cvFindContours(iplGray, g_storage, contours, CV_C, CV_C, CV_C);
cvZero(iplGray);
if(contours != null){
opencv_core.cvDrawContours(iplGray, contours, CvScalar.ONE, CvScalar.ONE, CV_C, CV_C, CV_C);
}
cvShowImage( "Contours", iplGray );
我认为它与 CvSeq contours = new CvSeq(iplGray);但我不明白为什么.有什么有用的想法吗?
I think it is related with CvSeq contours = new CvSeq(iplGray); but I don't understand why. Any helpful idea?
推荐答案
对于轮廓检测,我用过这个方法.表现不错.
For Contours Detection, I have used this method. It is performed well.
public static IplImage detectObjects(IplImage srcImage){
IplImage resultImage = cvCloneImage(srcImage);
CvMemStorage mem = CvMemStorage.create();
CvSeq contours = new CvSeq();
CvSeq ptr = new CvSeq();
cvFindContours(srcImage, mem, contours, Loader.sizeof(CvContour.class) , CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
CvRect boundbox;
for (ptr = contours; ptr != null; ptr = ptr.h_next()) {
boundbox = cvBoundingRect(ptr, 0);
cvRectangle( resultImage , cvPoint( boundbox.x(), boundbox.y() ),
cvPoint( boundbox.x() + boundbox.width(), boundbox.y() + boundbox.height()),
cvScalar( 0, 255, 0, 0 ), 1, 0, 0 );
}
return resultImage;
}
这篇关于在 JavaCV 或 OPENCV 中查找轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文