I'm trying to create an image depicting matches between keypoints in images generated from sift files, using the Features2d.drawMatches method from openCV java API. I can't seem to figure out what kind of argument the method will take as an output parameter - I keep getting the following Assertion Error:
OpenCV(3.4.1) Error: Assertion failed (!outImage.empty()) in
cv::drawKeypoints, file C:\build\master_winpack-bindings-win32-vc14-
static\opencv\modules\features2d\src\draw.cpp, line 115
Exception in thread "main" CvException [org.opencv.core.CvException:
cv::Exception: OpenCV(3.4.1) C:\build\master_winpack-bindings-win32-vc14-
static\opencv\modules\features2d\src\draw.cpp:115: error: (-215)
!outImage.empty() in function cv::drawKeypoints
]
at org.opencv.features2d.Features2d.drawMatches_1(Native Method)
at org.opencv.features2d.Features2d.drawMatches(Features2d.java:71)
at com.company.GUI.ImagesView.matchPoints(ImagesView.java:94)
at com.company.GUI.ImagesView.<init>(ImagesView.java:69)
at com.company.Main.main(Main.java:17)
My code:
private void matchPoints() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
MatOfKeyPoint matKey1 = new MatOfKeyPoint(keyPoints1);
MatOfKeyPoint matKey2 = new MatOfKeyPoint(keyPoints2);
MatOfDMatch matDMatch = new MatOfDMatch(matches);
Mat output = new Mat();
//output = new Mat(matKey1.rows(), matKey1.cols(), CvType.CV_8U, Scalar.all(0));
if (!output.empty())
System.out.println("not empty");
else
System.out.println("empty");
Features2d.drawMatches(mat1, matKey1, mat2, matKey2, matDMatch, output);
HighGui.imshow("Matches", output);
}
The exact same assertion error shows up whether or not I un-comment the commented line, despite the empty() check below returning different values for these two Mats. I'm at loss, help would be much appreciated.
答案 0 :(得分:0)
我无法发表评论,因此我必须写一个答案:
我遇到了同样的问题,并以某种方式解决了它。这不是依赖性错误-我已经解决了它,而无需更改依赖性(或导入的库)。
如果正确计算出匹配项,则在调用此函数时不会发生此特定错误。
在我的代码中,错误是计算函数的调用。我试图用FastFeatureDetector调用此函数-但我在某处已经读到该检测器找不到任何匹配项。
尝试计算
ORB extractor = ORB.create();
extractor.compute(currentFrame, keyPoints, imgDescriptor);
尝试计算imgDescriptor时,不会发生任何错误;匹配后,您应该能够绘制匹配。
希望,我可以帮助您或其他遇到这种错误的人。