java - drawMatches() 抛出 CvException:不支持的目标图像
问题描述
我正在我的徽标和输入图像之间绘制匹配项。该drawMatches
函数不起作用并引发异常。
这是我的代码:
Mat input = Imgcodecs.imread(inputAddress);
Mat logo = Imgcodecs.imread(logoList.getSelectionModel().getSelectedItem());
SIFT detector = SIFT.create(4, 3);
MatOfKeyPoint logoKeypoint = new MatOfKeyPoint();
MatOfKeyPoint inputKeypoint = new MatOfKeyPoint();
detector.detect(logo, logoKeypoint);
detector.detect(input, inputKeypoint);
Mat logoDes = new Mat();
Mat inputDes = new Mat();
detector.compute(logo, logoKeypoint, logoDes);
detector.compute(input, inputKeypoint, inputDes);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
MatOfDMatch matches = new MatOfDMatch();
matcher.match(logoDes, inputDes, matches);
HighGui.namedWindow("matches", 1);
Mat imgMatches = new Mat();
Features2d.drawMatches(logo, logoKeypoint, input, inputKeypoint, matches, imgMatches);
HighGui.imshow("matches", imgMatches);
例外:
Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.1.0) C:\Users\hennm\Downloads\opencv-4.1.0\modules\features2d\src\draw.cpp:128: error: (-2:Unspecified error) in function 'void __cdecl cv::_prepareImage(const class cv::debug_build_guard::_InputArray &,const class cv::Mat &)'
> Unsupported destination image:
> 'dst.type() == CV_8UC3 || dst.type() == CV_8UC4'
> where
> 'dst.type()' is 0 (CV_8UC1)
]
at org.opencv.features2d.Features2d.drawMatches_4(Native Method)
at org.opencv.features2d.Features2d.drawMatches(Features2d.java:116)
at sample.Controller.match(Controller.java:102)
sample.Controller.match(Controller.java:102)
线在哪里Features2d.drawMatches(logo, logoKeypoint, input, inputKeypoint, matches, imgMatches);
解决方案
推荐阅读
- python - JSONDecorderError:期望值
- c++ - VSCode 和 C 环境
- python - Xpath 和 css_selectors 无法提取动态内容。(使用 Python 和 Selenium)
- javascript - 如何让捆绑恐惧症在出口分析中显示不同的尺寸?
- android - 特定于应用程序的外部存储:其他应用程序如何访问它?
- python - 如何在pyspark的表达式中避免多个窗口函数
- assembly - 程序集计算变量的位置
- swift - 我如何在 ios 中集成万事达卡 sdk
- java - 无论如何要在 minecraft forge 1.12.2 中“等待 1 秒”?
- angular - 角度形式总是返回无效?