Ask Your Question

valder's profile - activity

2014-08-25 18:41:39 -0600 commented question Process video frame by frame in OpenCV on Android

@berak, I"m having a hard time extracting frames from a video. Can you show me what you did to do this? All the frames I extract come out all garbled. I'm not sure what is wrong. Any help would be appreciated.

2014-08-22 13:58:56 -0600 commented question Process video frame by frame in OpenCV on Android

Did you get any help on this? I'm in the same boat.

2014-08-22 13:56:43 -0600 asked a question calcOpticalFlowPyrLK never returns in Java call

Hello, I've been trying to port a C library into Java for my Android project. I'm not making a whole lot of progress. I'm taking in a video file and trying to do some analysis on the frames. I'm able to get all the way up to the point where I call Video.calcOpticalFlowPyrLK(). At this point the code just never returns. No exception is thrown or any messages printed to the log. Any suggestions? I've included some code snippets .

Thanks,

void DetectFrame(Mat currFrame)
{
    TermCriteria termcrit = new TermCriteria(TermCriteria.MAX_ITER | TermCriteria.EPS, 20, 0.03);
    Size subPixWinSize = new Size(10,10), winSize = new Size(31,31);

    Imgproc.cvtColor(currFrame, curr_, Imgproc.COLOR_BGR2GRAY);
    Imgproc.goodFeaturesToTrack(curr_, initialPoints, max_corners, 0.01, 10);

    Log.d(MotionTracker.class.getCanonicalName(), "features found: " + initialPoints.total());

    nextPoints = new MatOfPoint2f( initialPoints.toArray() );
    Log.d(TAG, "Number of features found : " + nextPoints.total());

    if(nextPoints.total() != 0) //Some weird problem that causes features to be found !!!
    {
        Size zeroZone = new Size(-1, -1);
        Imgproc.cornerSubPix(curr_, nextPoints, subPixWinSize, zeroZone, termcrit);
        Log.d(TAG, "sub pixel count: " + nextPoints.total());

        if(prev_.empty())
        {
            swapMatOfPoint2f();
            swapMat();
        }
    }
    else {
        Log.d(TAG, "No features found !");
    }
}


public boolean TrackFrame(Mat trackedFrame) {
    int i=0, k;
    MatOfPoint2f pt;
    TermCriteria termCriteria = new TermCriteria(TermCriteria.EPS | TermCriteria.MAX_ITER, 20, 0.03);
    Size subPixWinSize = new Size(10,10);
    Size winSize = new Size(5,5);
    if (prevPoints.empty() || (frame_count_ % 12) == 0) {
        DetectFrame(trackedFrame);
    }
    else {
        try {
             Imgproc.cvtColor(trackedFrame, curr_, Imgproc.COLOR_BGR2GRAY);
              Video.calcOpticalFlowPyrLK(prev_, curr_, prevPoints, nextPoints, status_, err_);

        } catch (Exception ex) {
            // do something with the exception
             ......
        }
2014-08-22 13:47:48 -0600 commented answer How to pass a MatOfKeyPoint and MatOfPoint2f to native code? (OpenCV 4 Android)

Hello, I'm having a hell of a time trying to get this to work. When I try Mat_to_vector_Point2f I get the following error in my log file (Android)

error()﹕ OpenCV Error: Assertion failed (channels() == CV_MAT_CN(dtype)) in void cv::Mat::copyTo(cv::OutputArray) const, file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/copy.cpp, line 212

Here's my code that sets up the call:

vector<cv::Point2f> points1, points2;
cv::Mat& previousMatPoints = *(cv::Mat *)addrInputPointsVector;
cv::Mat& nextMatPoints = *(cv::Mat *)addrOutputPointsVector;
Mat_to_vector_Point2f(previousMatPoints, points1);
Mat_to_vector_Point2f(nextMatPoints, points2);

I'm totally stumped. The Java code passes in the long values generated from the .getNativeObjAddr() calls