函数checkVector(2)在OpenCV中返回错误

时间:2015-03-17 11:38:39

标签: java opencv match shapes

我想匹配两个不同的轮廓,尤其是Mats of Hu moment,但函数Imgproc.matchShapes()会返回错误:

contour1.checkVector(2) >= 0 
&& 
contour2.checkVector(2) >= 0 
&& 
(contour1.depth() == CV_32F || contour1.depth() == CV_32S) 
&& 
contour1.depth() == contour2.depth() in function cv::matchShapes

所以,我从函数Imgproc.HuMoments()中返回了两个Hu时刻:

H1 = Mat [ 7*1*CV_64FC1, isCont=true, isSubmat=false, nativeObj=0xf8ec790, dataAddr=0xc572c00 ]
H2  = Mat [ 7*1*CV_64FC1, isCont=true, isSubmat=false, nativeObj=0xf8bcf70, dataAddr=0xc5dafa0 ]

然后我将它们转换为CvType.CvType.CV_32FC1,函数为:

H1.convertTo(H1, CvType.CV_32F);

但它也会返回错误,所以我认为这是因为H1.checkVector(2)= -1。但我该如何解决呢?

Caused by: CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\imgproc\src\contours.cpp:1936: error: (-215) contour1.checkVector(2) >= 0 && contour2.checkVector(2) >= 0 && (contour1.depth() == CV_32F || contour1.depth() == CV_32S) && contour1.depth() == contour2.depth() in function cv::matchShapes
]
at org.opencv.imgproc.Imgproc.matchShapes_0(Native Method)
at org.opencv.imgproc.Imgproc.matchShapes(Imgproc.java:7543)
at sample.Contour.MatchTemplate(Contour.java:264)
at sample.Controller.OnButtonMatchTemplate(Controller.java:167)
... 86 more
Exception in thread "JavaFX Application Thread" 

0 个答案:

没有答案