【问题标题】:Optical flow in AndroidAndroid中的光流
【发布时间】:2011-08-23 06:19:39
【问题描述】:

我们已经与 OpenCV 打交道两周以使其在 Android 上运行。 你知道我们在哪里可以找到光流的 Android 实现吗?如果用 OpenCV 实现就好了。

【问题讨论】:

    标签: android opencv vision opticalflow


    【解决方案1】:

    Openframeworks 内置了 openCV,以及许多其他有趣的库。它有一个非常优雅的结构,我已经将它与 android 一起使用,通过摄像头的运动估计来制作手机的虚拟鼠标。

    在此处查看 android 的端口http://openframeworks.cc/setup/android-studio/

    似乎他们最近添加了对 android studio 的支持,否则 eclipse 效果很好。

    【讨论】:

      【解决方案2】:

      试试这个

      @Override
      public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
      
          mRgba = inputFrame.rgba();
          if (mMOP2fptsPrev.rows() == 0) {
      
              //Log.d("Baz", "First time opflow");
              // first time through the loop so we need prev and this mats
              // plus prev points
              // get this mat
              Imgproc.cvtColor(mRgba, matOpFlowThis, Imgproc.COLOR_RGBA2GRAY);
      
              // copy that to prev mat
              matOpFlowThis.copyTo(matOpFlowPrev);
      
              // get prev corners
              Imgproc.goodFeaturesToTrack(matOpFlowPrev, MOPcorners, iGFFTMax, 0.05, 20);
              mMOP2fptsPrev.fromArray(MOPcorners.toArray());
      
              // get safe copy of this corners
              mMOP2fptsPrev.copyTo(mMOP2fptsSafe);
              }
          else
              {
              //Log.d("Baz", "Opflow");
              // we've been through before so
              // this mat is valid. Copy it to prev mat
              matOpFlowThis.copyTo(matOpFlowPrev);
      
              // get this mat
              Imgproc.cvtColor(mRgba, matOpFlowThis, Imgproc.COLOR_RGBA2GRAY);
      
              // get the corners for this mat
              Imgproc.goodFeaturesToTrack(matOpFlowThis, MOPcorners, iGFFTMax, 0.05, 20);
              mMOP2fptsThis.fromArray(MOPcorners.toArray());
      
              // retrieve the corners from the prev mat
              // (saves calculating them again)
              mMOP2fptsSafe.copyTo(mMOP2fptsPrev);
      
              // and save this corners for next time through
      
              mMOP2fptsThis.copyTo(mMOP2fptsSafe);
              }
      
      
          /*
          Parameters:
              prevImg first 8-bit input image
              nextImg second input image
              prevPts vector of 2D points for which the flow needs to be found; point coordinates must be single-precision floating-point numbers.
              nextPts output vector of 2D points (with single-precision floating-point coordinates) containing the calculated new positions of input features in the second image; when OPTFLOW_USE_INITIAL_FLOW flag is passed, the vector must have the same size as in the input.
              status output status vector (of unsigned chars); each element of the vector is set to 1 if the flow for the corresponding features has been found, otherwise, it is set to 0.
              err output vector of errors; each element of the vector is set to an error for the corresponding feature, type of the error measure can be set in flags parameter; if the flow wasn't found then the error is not defined (use the status parameter to find such cases).
          */
          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, colorRed, iLineThickness - 1);
      
                  Core.line(mRgba, pt, pt2, colorRed, iLineThickness);
                  }
              }
      
      return mRgba;
      
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-10
        • 1970-01-01
        相关资源
        最近更新 更多