FeatureDetector.detect()函数错误



我正在尝试使用FAST FeatureDetector来检测手机摄像头拍摄的视频的关键点。当我尝试运行matcher.match(descriptor1,descriptor2,matches)时,它出现了一个错误。

这是我的代码:

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);

这是我的日志输出:

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)

我已经尝试更改Mat类型(目前为CV_8UC4)。我只是不明白为什么当我试图控制比赛时会发生这种情况。

非常感谢您的帮助,谢谢!

您需要创建keypoints1和keypoints2对象。像

keypoints1 = new MatOfKeyPoint();

因为现在它们是空的;

相关内容

  • 没有找到相关文章

最新更新