Reputation: 73
I am trying using the FAST FeatureDetector to detect keypoints of the video taken by my cellphone camera. When I try to run matcher.match(descriptor1,descriptor2, matches), it comes to an error.
Here is my code:
private Mat bgMat; //contains the first frame taken by the camera
private Mat fgMat; //contains the second frame
private MatOfKeyPoint keypoints1;
private MatOfKeyPoint keypoints2;
private Mat descriptor1;
private Mat descriptor2;
FeatureDetector FAST = FeatureDetector.create(FeatureDetector.FAST);
keypoints1 = new MatOfKeyPoint();
keypoints2 = new MatOfKeyPoint();
descriptor1 =new Mat();
descriptor2 =new Mat();
matches= new MatOfDMatch();
FAST.detect(bgMat, keypoints1);
FAST.detect(fgMat, keypoints2);
DescriptorExtractor Extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
Extractor.compute(bgMat, keypoints1, descriptor1);
Extractor.compute(fgMat, keypoints2,descriptor2);
DescriptorMatcher matcher =DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
matcher.match(descriptor1,descriptor2, matches);
Features2d.drawMatches(bgMat, keypoints1, fgMat, keypoints2, matches, inputFrame);
Here is my logcat out put:
02-11 13:00:25.926: E/cv::error()(16153): OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool), file /home/oleg/sources/opencv/modules/core/src/stat.cpp, line 1803
02-11 13:00:25.926: W/dalvikvm(16153): threadid=11: thread exiting with uncaught exception (group=0x415eb2a0)
02-11 13:00:25.926: E/AndroidRuntime(16153): FATAL EXCEPTION: Thread-3281
02-11 13:00:25.926: E/AndroidRuntime(16153): CvException [org.opencv.core.CvException: /home/oleg/sources/opencv/modules/core/src/stat.cpp:1803: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool)
02-11 13:00:25.926: E/AndroidRuntime(16153): ]
02-11 13:00:25.926: E/AndroidRuntime(16153): at org.opencv.features2d.DescriptorMatcher.match_1(Native Method)
02-11 13:00:25.926: E/AndroidRuntime(16153): at org.opencv.features2d.DescriptorMatcher.match(DescriptorMatcher.java:437)
02-11 13:00:25.926: E/AndroidRuntime(16153): at com.example.cvcamt.MainActivity.onCameraFrame(MainActivity.java:152)
02-11 13:00:25.926: E/AndroidRuntime(16153): at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:283)
02-11 13:00:25.926: E/AndroidRuntime(16153): at org.opencv.android.NativeCameraView$CameraWorker.run(NativeCameraView.java:144)
02-11 13:00:25.926: E/AndroidRuntime(16153): at java.lang.Thread.run(Thread.java:856)
I've tried changing the Mat type (it is currently CV_8UC4). I just can't figure out why when I try to run the match this is happening.
Any help is much appreciated, Thanks!
Upvotes: 0
Views: 1545
Reputation: 4119
You need to create your keypoints1 and keypoints2 objects. Like
keypoints1 = new MatOfKeyPoint();
because now they are null;
Upvotes: 1