我正在尝试使用 openCV java API 中的 Features2d.drawMatches 方法创建一个图像,描绘从 sift 文件生成的图像中的关键点之间的匹配。我似乎无法弄清楚该方法将采用哪种参数作为输出参数 - 我不断收到以下断言错误:
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)
我的代码:
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);
}
尽管下面的 empty() 检查为这两个 Mats 返回了不同的值,但无论我是否取消注释注释行,都会显示完全相同的断言错误。我不知所措,非常感谢您的帮助。