Calculating frame difference in Android

asked 2014-12-08 01:01:26 -0600

Hi, I'm trying to calculate the frame difference for my research on embedded systems. I want to apply a black/white mask to differences exceeding the threshold. However, the OpenCV libs only provide the one with colors, so I had to do the masking myself. I encountered a problem as I get the values form Mat , process it, and put back.


Here's my codes and error messages(btw, my Mat have type CV_8UC4, and I had checked that src.dims == 2)

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    current = inputFrame.rgba();
    if(first)
    {
        previous = inputFrame.rgba();
        first = false;
    }

    current.get(0, 0, buffer);
    previous.get(0, 0, buffer2);

    for(int i = 0 ; i < buffer.length ; i=i+4)
    {
        buffer_d[i] = 0x00;
        buffer_d[i+1] = 0x00;
        buffer_d[i+2] = 0x00;
        buffer_d[i+3] = 0x00;
    }

    difference.put(0, 0, buffer_d);

    previous = inputFrame.rgba();

    return difference;
}

E/cv::error()(24197): OpenCV Error: Assertion failed (src.dims == 2 && info.height ==(uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97

E/org.opencv.android.Utils(24197): nMatToBitmap catched cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

E/CameraBridge(24197): Mat type: Mat [ 320240CV_8UC4, isCont=true, isSubmat=false, nativeObj=0x72c122a8, dataAddr=0x7a8d8010 ]

E/CameraBridge(24197): Bitmap type: 320*240

E/CameraBridge(24197): Utils.matToBitmap() throws an exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

edit retag flag offensive close merge delete