Ask Your Question
0

Take frame after some millisecond

asked 2015-09-11 14:27:21 -0600

Nikre93 gravatar image

updated 2015-09-12 02:41:44 -0600

berak gravatar image

Hi, this is my problem: I wuold like to implement a motion detection. In Internet i found that the motion is captured using two different frame, and with the function Core.absdiff() put the differce in a new Mat. I haven't undestand how i take a frame, and after 0.1 second take another frame to do the difference. How i can do?

Thanks for yuor time.

edit retag flag offensive close merge delete

Comments

In a first way I used an Array list, but doesn't work, because i done a difference of two equal frame: result, a black screen.

Nikre93 gravatar imageNikre93 ( 2015-09-11 14:38:39 -0600 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2015-09-20 01:24:08 -0600

RolandC gravatar image

You could do it e. g. this way:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

VideoCapture videoCapture = new VideoCapture();
videoCapture.open(0);

...

Mat mat = new Mat();
Mat prevMat = null;
Mat diffMat = new Mat();

while( true) {

    // get frame
    videoCapture.read(mat);

    // difference
    if( prevMat != null) {
        Core.absDiff(mat, prevMat, diffMat);
    }

    // remember mat
    prevMat = mat.clone();

    // wait
    Thread.sleep(100);
}

The difference image is in diffMat.

edit flag offensive delete link more

Comments

if i would use the mat, and camera input without using the VideoCapture. Iìm working in real time...

Nikre93 gravatar imageNikre93 ( 2015-10-16 08:46:38 -0600 )edit
0

answered 2015-09-11 16:23:57 -0600

albertJ gravatar image

Something like this will get you two images and save them to two matrixes then you can always pass them to functions from inside the loop for processing.

  VideoCapture stream(1);
  if(!stream.isOpened()){
    cout << "Video stream unable to be opened exiting.." << endl;
    exit(0);
  } 

  Mat img1, img2;

  namedWindow("curImg", CV_WINDOW_AUTOSIZE);

  int w_width = 200;
  int w_height = 75;
  int counter=0;
  int delay = 100; // delay in milliseconds

while(true){
    cap >> img;
    Mat frame = Mat(w_height, w_width, CV_8UC3, Scalar(255,255,255));

    if(counter%2 ==0){
      frame.coppyTo(img1);
    }else{
      frame.copyTo(img2);
    }

    imshow("curImg", frame);
    waitKey(delay);
    counter++;
 }
edit flag offensive delete link more

Comments

i try, i forget to add in the ask that i program in java, an app for android

Nikre93 gravatar imageNikre93 ( 2015-09-12 04:15:47 -0600 )edit
1

oh i've only worked with the c++ api, so cant help you there

albertJ gravatar imagealbertJ ( 2015-09-12 05:31:43 -0600 )edit

For java you can use HighGui.waitKey(delay);

Vardan16 gravatar imageVardan16 ( 2018-07-14 22:54:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-11 14:27:21 -0600

Seen: 1,289 times

Last updated: Sep 20 '15