本文介绍了在JavaCV或OPENCV中查找轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,但我不知道是什么!我有下一个代码,当我调试它时,调试器停在

  IplImage iplGray = cvCreateImage(cvGetSize(iplUltima) ,8,1); 
CvMemStorage g_storage = null;
CvSeq轮廓= new CvSeq(iplGray);

opencv_imgproc.cvCvtColor(iplUltima,iplGray,opencv_imgproc.CV_BGR2GRAY);
opencv_imgproc.cvThreshold(iplGray,iplGray,100,255,opencv_imgproc.CV_THRESH_BINARY);

//这里,下一行:
opencv_imgproc.cvFindContours(iplGray,g_storage,contour,CV_C,CV_C,CV_C);
cvZero(iplGray);
if(contours!= null){
opencv_core.cvDrawContours(iplGray,contour,CvScalar.ONE,CvScalar.ONE,CV_C,CV_C,CV_C);
}
cvShowImage(Contours,iplGray);

我认为这与CvSeq轮廓= new CvSeq(iplGray)有关。但我不明白为什么。
任何有用的想法?

解决方案

对于轮廓检测,我已经使用了这个方法。



pre $ public static IplImage detectObjects(IplImage srcImage){

IplImage resultImage = cvCloneImage (srcImage);

CvMemStorage mem = CvMemStorage.create();
CvSeq轮廓= 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;

(ptr = contours; ptr!= null; ptr = ptr.h_next()){
boundbox = cvBoundingRect(ptr,0);

cvRectangle(boundbox.x()+ boundbox.width(),boundbox.y() + boundbox.height()),
cvScalar(0,255,0,0),1,0,0);
}

return resultImage;
}


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 );

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中查找轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 14:42