【发布时间】:2019-11-20 21:11:26
【问题描述】:
我试图从生成的船体点计算船体面积
convexHull().
我跟着OpenCV Python tutorial(因为没有Java教程)和代码完成摆弄。
这是代码:
Imgproc.findContours(patternEdges, patternContours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
MatOfInt patternHull = new MatOfInt();
Imgproc.convexHull(patternContours.get(0), patternHull);
Imgproc.contourArea(pickPoints(patternContours.get(0), patternHull)); // fails here
但这会引发以下异常:
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.1.2) /home/build/git/opencv/modules/imgproc/src/shapedescr.cpp:274: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'contourArea'] at org.opencv.imgproc.Imgproc.contourArea_1(Native Method) at org.opencv.imgproc.Imgproc.contourArea(Imgproc.java:1607) at com.acme.opencv.Test.main(Test.java:94)
显然矩阵内部数据类型是错误的。但是为什么,以及如何转换它?
我正在使用 OpenCV 4.1.2。
【问题讨论】:
标签: java opencv opencv-contour