我正在尝试使用OpenCV camShift函数在android上实现对象跟踪应用程序。我正在使用我的Android平板电脑的相机来获取图像帧。我在图像框内定义了一个我想要跟踪的空间矩形。然后我将这两个值传递给Video.Camshift函数以及终端条件。在我启动应用程序后,我得到了:
OpenCV错误:断言失败 - 错误
以下是相关代码:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat scene = inputFrame.rgba();
if(trackingFrame == null){
trackingFrame = new Rect(scene.cols()/2,scene.rows()/2,50,50);
}
System.out.println(trackingFrame.size().toString());
RotatedRect box =Video.CamShift(scene, trackingFrame, new TermCriteria(TermCriteria.EPS,10,1));
trackingFrame = box.boundingRect();
Point pt1 =new Point(trackingFrame.x,trackingFrame.y);
Point pt2 =new Point(trackingFrame.x+trackingFrame.width,trackingFrame.y+trackingFrame.height);
Scalar RED = new Scalar(255,0,0);
Imgproc.rectangle(scene, pt1, pt2, RED);
return scene;
}
这是我得到的错误:
E/cv::error()(19177): OpenCV Error: Assertion failed (cn == 1) in int cv::meanShift(cv::InputArray, cv::Rect&, cv::TermCriteria), file /home/maksim/workspace/android-pack/opencv/modules/video/src/camshift.cpp, line 59
E/org.opencv.video(19177): video::CamShift_10() caught cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/video/src/camshift.cpp:59: error: (-215) cn == 1 in function int cv::meanShift(cv::InputArray, cv::Rect&, cv::TermCriteria)
W/dalvikvm(19177): threadid=11: thread exiting with uncaught exception (group=0x42f05500)
E/AndroidRuntime(19177): FATAL EXCEPTION: Thread-8274
E/AndroidRuntime(19177): CvException [org.opencv.core.CvException: cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/video/src/camshift.cpp:59: error: (-215) cn == 1 in function int cv::meanShift(cv::InputArray, cv::Rect&, cv::TermCriteria)
我真的不明白问题是什么,因为错误消息没有说明具体内容。有谁能够帮我?
答案 0 :(得分:-1)
好的,我发现了我的错误。 而不是使用相机输入,我首先必须:
calcHist
calcBackProject
函数calcBackProject
- 函数Video.CamShift
的输出