0

我正在尝试使用 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);

这是我的 logcat 输出:

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)。我只是不明白为什么当我尝试进行比赛时会发生这种情况。

非常感谢任何帮助,谢谢!

4

1 回答 1

1

您需要创建您的 keypoints1 和 keypoints2 对象。喜欢

keypoints1 = new MatOfKeyPoint();

因为现在它们是空的;

于 2013-02-11T19:43:07.017 回答