0

我正在研究 eclipse + opencv 2.4.6 + java api。

现在我有这个编译错误:

OpenCV Error: Assertion failed (ptnum > 3) in unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1969 Exception in thread "main" CvException [org.opencv.core.CvException: ..\..\..\src\opencv\modules\imgproc\src\contours.cpp:1969: error: (-215) ptnum > 3 ]

at org.opencv.imgproc.Imgproc.convexityDefects_0(Native Method)
at org.opencv.imgproc.Imgproc.convexityDefects(Imgproc.java:3170)

部分代码为:

     List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
     Mat hierarchy = new Mat();
     Imgproc.findContours(imgframe,contours , hierarchy,Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE,new Point(0,0));

                for(int i=0;i<contours.size();i++) {

                Imgproc.drawContours(imgframe, contours,i,new Scalar(255,0,255),2,8,hierarchy,0,new Point());
                MatOfInt hull_=new MatOfInt();

                MatOfInt4 convexityDefects=new MatOfInt4();
                Imgproc.convexHull(contours.get(0), hull_);
                Imgproc.convexityDefects(contours.get(0), hull_, convexityDefects);

                }

你能帮助我吗??谢谢

4

1 回答 1

0

我认为问题在于凸包中的点数。它应该至少有 3 个点才能使使用成为convexityDefect()可能。可以使用循环if中的an 轻松检查:for

if(hull_.rows() >= 3){
    Imgproc.convexityDefects(contours.get(0), hull_, convexityDefects);
}
于 2013-08-25T09:22:46.483 回答