Ask Your Question

Aaron666's profile - activity

2020-09-27 06:00:07 -0600 received badge  Supporter (source)
2020-09-27 06:00:02 -0600 commented answer try to read different frame by videocapture but failed

yes i tried and the solution can work. tks~

2020-09-27 05:59:14 -0600 marked best answer try to read different frame by videocapture but failed

Hi all, this is my way i try to read and save video's different frame. below is my code, but i found that i got the same images.(i'm sure i keep moving in front of the camera lol)

pls help me to find what i need to do. thanks in advance!!

#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace cv;
using namespace std;

int main(int, char**)
{
    Mat frame;
    VideoCapture cap;
    int deviceID = 0;             // 0 = open default camera
    int apiID = cv::CAP_ANY;      // 0 = autodetect default API
    cap.open(deviceID + apiID);

    if (!cap.isOpened()) {
        cerr << "ERROR! Unable to open camera\n";
        return -1;
    }

    //--- GRAB AND WRITE LOOP
    cout << "Start grabbing" << endl
        << "Press any key to terminate" << endl;

int cnt = 0;
Mat frm_test[3];
clock_t start, finish;
start = clock();

for (;;)
{
    // wait for a new frame from camera and store it into 'frame'
    cap.read(frame);
    // check if we succeeded
    if (frame.empty()) {
        cerr << "ERROR! blank frame grabbed\n";
        break;
    }

    finish = clock();
    if ((cnt < 3) && ((finish - start)/CLOCKS_PER_SEC > 1.0)) {
        frm_test[cnt] = frame;
        start = clock();
        cnt++;
    }

        // covert color to gray
        //cvtColor(frame, frame, cv::COLOR_RGB2GRAY);

        // show live and wait for a key with timeout long enough to show images
        imshow("Live", frame);
        if (waitKey(5) >= 0) {
            cout << "Exit requested" << endl;
            destroyAllWindows();
            break;
        }

    }
    // the camera will be deinitialized automatically in VideoCapture destructor

    imshow("frm 1", frm_test[0]);
    imshow("frm 2", frm_test[1]);
    imshow("frm 3", frm_test[2]);

    waitKey(0);
    return 0;
}
2020-09-27 05:59:14 -0600 received badge  Scholar (source)
2020-09-27 05:59:07 -0600 commented answer try to read different frame by videocapture but failed

i see...... i don't really know about shallow and deep copy problem. i'll research it. your answer can work! tks a lot!!

2020-09-27 05:19:57 -0600 received badge  Student (source)
2020-09-27 04:59:58 -0600 asked a question try to read different frame by videocapture but failed

try to read different frame by videocapture but failed Hi all, this is my way i try to read and save video's different f