6

我正在尝试使用 openCV http://code.google.com/p/android-opencv/在 android 中实现光流。基本上我想构建这样的东西http://www.youtube.com/watch?v=P_Sjn67jIJY。无论如何,因为我是 android 开发的新手,任何人都可以在某个地方指导以构建类似视频中的东西吗?我已经将 opencv 端口安装到 android 并使用 eclipse 成功构建了 cvcamera 示例。谢谢,灭霸

4

4 回答 4

1

请参阅此斯坦福 OpenCV 光流链接。事情应该以相同的方式工作,只是由于 1.x 与 2.x 的 C 与 C++ API 问题,调用可能略有不同。

只需编辑 CVCamera 示例,它应该很快。在 CVCamera 开始工作后的大约一个小时内,我制作了一个实时人脸检测应用程序。

于 2011-06-28T17:06:37.707 回答
0

此代码将帮助您获得光学矢量。它会跟踪他们

@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;

    }
于 2015-01-12T15:00:05.683 回答
0

虽然我也在尝试做同样的事情,但现在 OpenCV4Android 中似乎对光流有更多的支持。查看 org.opencv.video OpenCV Java 文档中的 API 我看到了 calcOpticalFlowPyrLK 和 calcOpticalFlowFarneback。我能够让 calcOpticalFlowFarneback 工作(尽管结果似乎不是很好,可能需要调整参数) calcOpticalFlowPyrLK 被证明是棘手的。我似乎无法将 FeatureDetector 类 (MatOfKeyPoint) 返回的关键点转换为 calcOpticalFlowFarneback (MatOfPoint2f)其他线程所需的点

于 2013-01-15T21:29:01.670 回答
0

访问http://opencv.willowgarage.com/wiki/Android2.3.0,OpenCV 2.3.0 Release Candidate 对 Android 有很好的支持。里面有光流..用过

于 2011-06-28T17:13:19.510 回答