我正在使用 JavaCV 开发一个形状识别项目,并且我找到了一些 OpenCV 代码来识别特定阈值图像中的凸形状。我试图将它从 openCV 转换为 javaCV。但是当我运行代码时,它卡在了检查轮廓的时候。任何人都可以帮助找到错误?谢谢。
IplImage detectThrs = getThresholdImage(img);
System.err.println("Stucked!!");
CvMemStorage storage = CvMemStorage.create();
CvSeq contour = new CvSeq(null);
cvFindContours(detectThrs, storage, contour, Loader.sizeof(CvContour.class), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
System.err.println("Stucked 2 !!");
CvSeq approx = null;
CvRect bound = null;
CvRect boundMax = null;
CvRect pos = null;
while (contour != null && !contour.isNull()) {
System.err.println("Stucked in while!!");
bound = cvBoundingRect(contour, 0);
approx = cvApproxPoly(contour, Loader.sizeof(CvContour.class), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contour) * 0.02, 0);
if(cvCheckContourConvexity(approx) != 0){
if(bound.width() > 4 || bound.height() > 4){
cvRectangle(
detectThrs,
cvPoint(bound.x(), bound.y()),
cvPoint(bound.x()+bound.width(), bound.y()+bound.height()),
CvScalar.RED,4,
CV_AA, 0
);//2 is thickness CV_AA is type of line 0 means no shift
//cvSaveImage(++ii + "colorMaskTest.jpg", detectThrs);
paint(img, bound.x(), bound.y());
}
}
}
contour = contour.h_next();
}