I'm drawing matches between my logo and my input image. The drawMatches
function didn't work and thrown exception.
Here is my code:
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);
The exception:
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)
Where sample.Controller.match(Controller.java:102)
is the line Features2d.drawMatches(logo, logoKeypoint, input, inputKeypoint, matches, imgMatches);