问题描述
在使用Haar Cascade检测后,我正在尝试在android中使用光流跟踪对象,如下面的代码所示,我遇到了这个错误,谁能帮我这个
E/cv::error(): OpenCV(3.4.12) 错误:断言失败 ((npoints = prevPtsMat.checkVector(2,CV_32F,true)) >= 0) in virtual void cv::{anonymous} ::SparsePyrLKOpticalFlowImpl::calc(cv::InputArray,cv::InputArray,cv::InputOutputArray,cv::OutputArray,cv::OutputArray),文件/build/3_4_pack-android/opencv/modules/视频/src/lkpyramid.cpp,第 1259 行 E/org.opencv.video: video::calcopticalFlowPyrLK_15() 捕获 cv::Exception: OpenCV(3.4.12) /build/3_4_pack-android/opencv/modules/video/src/lkpyramid.cpp:1259: 错误: ( -215:Assertion Failed) (npoints = prevPtsMat.checkVector(2,true)) >= 0 in function 'virtual void cv::{anonymous}::SparsePyrLKOpticalFlowImpl::calc(cv::InputArray,cv::OutputArray)' E/AndroidRuntime:致命异常:线程 2 进程:opencv.org,PID:31380 CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.12) /build/3_4_pack-android/opencv/modules/video/src/lkpyramid.cpp:1259: 错误: (-215:Assertion Failed ) (npoints = prevPtsMat.checkVector(2,cv::OutputArray)' ]
enter code hereMatOfRect cars = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) {
if (mJavaDetector != null) {
mJavaDetector.detectMultiScale(matGray,cars,1.1,2,// Todo: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteCarSize,mAbsoluteCarSize),new Size());
}
}
else {
Log.e(TAG,"Detection method is not selected!");
}
Rect[] carsArray = cars.toArray();
ArrayList<Point> CurrentCars = new ArrayList<>();
for (int i = 0; i < carsArray.length; i++)
{
Imgproc.rectangle(matRGB,carsArray[i].tl(),carsArray[i].br(),CAR_RECT_COLOR,3);
xCenter = (carsArray[i].x + carsArray[i].width + carsArray[i].x) / 2;
yCenter = (carsArray[i].y + carsArray[i].y + carsArray[i].height) / 2;
Point center = new Point(xCenter,yCenter);
CurrentCars.add(center);
Imgproc.putText(matRGB,"[" + center.x + "," + center.y + "]",new Point(center.x + 20,center.y + 20),Core.FONT_HERShey_SIMPLEX,0.7,new Scalar(255,255,255));
}
if (prevIoUsPoints.empty()){
prevIoUsPoints.fromList(CurrentCars);
matGray.copyTo(matPrevGray);
}
currentPoints = new MatOfPoint2f();
MatOfByte status = new MatOfByte();
MatOfFloat err = new MatOfFloat();
TermCriteria criteria = new TermCriteria(TermCriteria.COUNT + TermCriteria.EPS,10,0.03);
Video.calcopticalFlowPyrLK(matPrevGray,matGray,prevIoUsPoints,currentPoints,status,err);
byte StatusArr[] = status.toArray();
Point p0Arr[] = prevIoUsPoints.toArray();
Point p1Arr[] = currentPoints.toArray();
ArrayList<Point> good_new = new ArrayList<>();
for (int i = 0; i<StatusArr.length ; i++ ) {
if (StatusArr[i] == 1) {
good_new.add(p1Arr[i]);
Imgproc.line(matRGB,p1Arr[i],p0Arr[i],0),2);
Imgproc.circle(matRGB,5,-1);
}
}
currentPoints.copyTo(prevIoUsPoints);
matGray.copyTo(matPrevGray);
解决方法
matPrevGray
为空。这就是它所说的。