我正在編寫代碼以在camerapreview中查找drawable中的類似對象。我正在使用最新的Opencv 2.4.4。匹配器斷言失敗錯誤opencv Android
下面是我的函數和logcat的輸出。我做錯了什麼,我得到這樣的輸出?
public void detect_image (Mat mRgba) {
object_desc = new Mat();
scene_desc = new Mat();
object_keys = new MatOfKeyPoint();
scene_keys = new MatOfKeyPoint();
matches = new MatOfDMatch();
good_matches = new MatOfDMatch();
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.sto);
Utils.bitmapToMat(image,object);
surf = FeatureDetector.create(FeatureDetector.FAST);
surf.detect(object, object_keys);
surf.detect(mRgba, scene_keys);
surfEX = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
surfEX.compute(object, object_keys, object_desc);
surfEX.compute(mRgba, scene_keys, scene_desc);
dm = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_SL2);
dm.match(object_desc, scene_desc, matches);
double max_dist = 0;
double min_dist = 100;
for(int i = 0; i < object_desc.rows(); i++)
{ double dist = matches.toArray()[i].distance;
if(dist < min_dist) min_dist = dist;
if(dist > max_dist) max_dist = dist;
}
for(int i = 0; i < object_desc.rows(); i++)
{ MatOfDMatch temp = new MatOfDMatch();
if(matches.toArray()[i].distance < 3*min_dist)
{ temp.fromArray(matches.toArray()[i]);
good_matches.push_back(temp);
}
}
}
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
detect_image(mRgba);
return inputFrame.rgba();
}
的logcat:
03-27 01:55:31.258: E/cv::error()(564): 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/reports/ci/slave/50-SDK/opencv/modules/core/src/stat.cpp,
line 1803
哪一行正好是在此斷言失敗?你確定'surf.detect()'可以接受一個位圖作爲輸入嗎?它不應該是一個墊子? – JonesV 2013-03-27 06:42:31
surf.detect()需要墊子和物體,而mRgba是墊子。下面的代碼導致這些問題: dm.match(object_desc,scene_desc,matches); – Martus0 2013-03-27 10:40:01
我的錯誤,我沒有見過'Utils.bitmapToMat()'。你是否手動驗證了'object_desc.type == scene_desc.type'和'object_desc.cols == object_scene.cols'?顯然你的'object_desc'和'scene_desc'之間有某種不兼容...... – JonesV 2013-03-27 12:41:14