简体   繁体   中英

OpenCV Error: Assertion failed (ptnum > 3) in unknown function, file (Java + opencv 2.4.6)

I'm working on eclipse + opencv 2.4.6 + java api.

Now i have this compilation error :

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)

The partial code is:

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

                }

Can you help me?? Thank's

I think the problem lies in the number of points in your convex hull. It should have at least 3 points to make using the convexityDefect() possible. It can easily be checked using an if in the for loop:

if(hull_.rows() >= 3){
    Imgproc.convexityDefects(contours.get(0), hull_, convexityDefects);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM