Android - calcOpticalFlowPyrLK:断言失败

时间:2015-04-03 11:46:06

标签: java android opencv image-processing opticalflow

我正在开发一种基于OPENCV的calcOpticalFlowPyrLK的光流方法。我试过这段代码

 public Mat optical2(){

          Scalar red = new Scalar(255,0,0,255);

          if(mMOP2fptsPrev.rows() == 0) {

              Imgproc.cvtColor(mRgba, matOpFlowThis, Imgproc.COLOR_RGBA2GRAY);

              matOpFlowThis.copyTo(matOpFlowPrev);

              Imgproc.goodFeaturesToTrack(matOpFlowPrev, MOPcorners, iGFFTMax, 0.05, 20);
              mMOP2fptsPrev.fromArray(MOPcorners.toArray());

              mMOP2fptsPrev.copyTo(mMOP2fptsSafe);
              }
          else
              {

              matOpFlowThis.copyTo(matOpFlowPrev);

              Imgproc.cvtColor(mRgba, matOpFlowThis, Imgproc.COLOR_RGBA2GRAY);

              Imgproc.goodFeaturesToTrack(matOpFlowThis, MOPcorners, iGFFTMax, 0.05, 20);
              mMOP2fptsThis.fromArray(MOPcorners.toArray());

              mMOP2fptsSafe.copyTo(mMOP2fptsPrev);

              mMOP2fptsThis.copyTo(mMOP2fptsSafe);
              }

          Video.calcOpticalFlowPyrLK(matOpFlowPrev, matOpFlowThis, mMOP2fptsPrev, mMOP2fptsThis, mMOBStatus, mMOFerr);

          cornersPrev = mMOP2fptsPrev.toList();
          cornersThis = mMOP2fptsThis.toList();
          byteStatus = mMOBStatus.toList();
          y = byteStatus.size() - 1;
          for (x = 0; x < y; x++) {
              if (byteStatus.get(x) == 1) {
                  pt = cornersThis.get(x);
                  pt2 = cornersPrev.get(x);
                  Core.circle(mRgba, pt, 5, red, iLineThickness - 1);    
                  Core.line(mRgba, pt, pt2, red, iLineThickness);
                  }
              }

        return mRgba;
      } 

但我发现了这个错误:

  

04-03 13:19:35.170:E / cv :: error()(17831):OpenCV错误:断言   失败((npoints = prevPtsMat.checkVector(2,CV_32F,true))&gt; = 0)in   void cv :: calcOpticalFlowPyrLK(cv :: InputArray,cv :: InputArray,   cv :: InputArray,cv :: InputOutputArray,cv :: OutputArray,   cv :: OutputArray,cv :: Size,int,cv :: TermCriteria,int,double),file   /home/reports/ci/slave_desktop/50-SDK/opencv/modules/video/src/lkpyramid.cpp,   845 04-03 13:19:35.170:E / org.opencv.video(17831):   video :: calcOpticalFlowPyrLK_12()抓住了cv ::异常:   /home/reports/ci/slave_desktop/50-SDK/opencv/modules/video/src/lkpyramid.cpp:845:   错误:(-215)(npoints = prevPtsMat.checkVector(2,CV_32F,true))&gt; = 0   在函数void cv :: calcOpticalFlowPyrLK(cv :: InputArray,   cv :: InputArray,cv :: InputArray,cv :: InputOutputArray,cv :: OutputArray,   cv :: OutputArray,cv :: Size,int,cv :: TermCriteria,int,double)04-03   13:19:35.170:W / dalvikvm(17831):threadid = 11:线程退出   未捕获的异常(组= 0x40f19930)04-03 13:19:35.170:   E / AndroidRuntime(17831):致命异常:Thread-12741 04-03   13:19:35.170:E / AndroidRuntime(17831):CvException   [org.opencv.core.CvException:cv :: Exception:   /home/reports/ci/slave_desktop/50-SDK/opencv/modules/video/src/lkpyramid.cpp:845:   错误:(-215)(npoints = prevPtsMat.checkVector(2,CV_32F,true))&gt; = 0   在函数void cv :: calcOpticalFlowPyrLK(cv :: InputArray,   cv :: InputArray,cv :: InputArray,cv :: InputOutputArray,cv :: OutputArray,   cv :: OutputArray,cv :: Size,int,cv :: TermCriteria,int,double)04-03   13:19:35.170:E / AndroidRuntime(17831):] 04-03 13:19:35.170:   E / AndroidRuntime(17831):at   org.opencv.video.Video.calcOpticalFlowPyrLK_2(原生方法)04-03   13:19:35.170:E / AndroidRuntime(17831):at   org.opencv.video.Video.calcOpticalFlowPyrLK(Video.java:501)04-03   13:19:35.170:E / AndroidRuntime(17831):at   org.opencv.samples.facedetect.FdActivity.optical2(FdActivity.java:374)   04-03 13:19:35.170:E / AndroidRuntime(17831):at   org.opencv.samples.facedetect.FdActivity.onCameraFrame(FdActivity.java:305)   04-03 13:19:35.170:E / AndroidRuntime(17831):at   org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)   04-03 13:19:35.170:E / AndroidRuntime(17831):at   org.opencv.android.JavaCameraView $ CameraWorker.run(JavaCameraView.java:328)   04-03 13:19:35.170:E / AndroidRuntime(17831):at   java.lang.Thread.run(Thread.java:856)

你能帮帮我吗?

0 个答案:

没有答案