有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java drawMatches()引发异常:不支持的目标映像

我正在绘制我的徽标和输入图像之间的匹配。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);


共 (0) 个答案