我正在使用eclipse + opencv 2.4.6 + java api。OpenCV錯誤:斷言失敗(ptnum> 3)在未知函數中,文件(Java + opencv 2.4.6)
現在我有這樣的編譯錯誤:
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'。它應該很容易檢查... – Mahm00d
Mahmm00d哇!解決,只需檢查hull_.width()> = 3!非常感謝你!:) – user2715082
很高興我可以幫忙:)。我想我最好把它作爲答案發布(以備參考)。 – Mahm00d