gpt4 book ai didi

opencv - 在 JavaCV 或 OPENCV 中查找轮廓

转载 作者:太空宇宙 更新时间:2023-11-03 20:58:29 24 4
gpt4 key购买 nike

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

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); 有关但我不明白为什么。有什么有用的想法吗?

最佳答案

Contours Detection,我用过这种方法。它表现良好。

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

关于opencv - 在 JavaCV 或 OPENCV 中查找轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10668573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com