I wanted to detect the movement by calculating the difference between the two frames entering the camera, and displayed this difference on the phones screen. I have to override the OnCameraFrame() method, so I did:
@Override public Mat onCameraFrame(Mat inputFrame) { inputFrame.copyTo(current); Core.absdiff(current, previous, difference); current.copyTo(previous); return difference; }
but unfortunately the application crashes and I get:
06-13 18:17:30.000: E/cv::error()(13097): OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in void cv::arithm_op(cv::InputArray, cv::InputArray, cv::OutputArray, cv::InputArray, int, void (**)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, cv::Size, void*), bool, void*), file /home/reports/ci/slave/50-SDK/opencv/modules/core/src/arithm.cpp, line 1277 06-13 18:17:30.005: W/dalvikvm(13097): threadid=11: thread exiting with uncaught exception (group=0x411df2a0) 06-13 18:17:30.005: E/AndroidRuntime(13097): FATAL EXCEPTION: Thread-983 06-13 18:17:30.005: E/AndroidRuntime(13097): CvException [org.opencv.core.CvException: /home/reports/ci/slave/50-SDK/opencv/modules/core/src/arithm.cpp:1277: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function void cv::arithm_op(cv::InputArray, cv::InputArray, cv::OutputArray, cv::InputArray, int, void (**)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, cv::Size, void*), bool, void*)
Full class code:
package com.example.szpieg2; import org.opencv.android.BaseLoaderCallback; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Range; import org.opencv.core.Size; import android.app.Activity; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.Window; import android.view.WindowManager; public class TrackActivity extends Activity implements CvCameraViewListener { private Mat current; private CameraBridgeViewBase cameraView; private Mat previous; private Mat difference;
EDIT I installed openCV on the usign openCV manager device. All training materials added to OpenCV work on this device. Samsung Galaxy Note 2 device. The library project uses OpenCV 2.4.3 , and this one should stay.
[/ EDIT]