繁体   English   中英

OpenCV错误:未知函数,文件(Java + opencv 2.4.6)中的断言失败(ptnum> 3)

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

我正在使用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);

                }

你能帮助我吗?? 谢谢

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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