Ask Your Question

thh15's profile - activity

2020-04-09 12:13:43 -0600 received badge  Popular Question (source)
2017-05-15 07:32:03 -0600 commented answer capture and save with 2 webcams C++

thanks ! !

2017-05-15 07:08:19 -0600 commented answer capture and save with 2 webcams C++

What do i need to change to get higher quality pictures ?

2017-05-14 12:12:04 -0600 received badge  Scholar (source)
2017-05-14 12:12:00 -0600 commented answer capture and save with 2 webcams C++

thanks again for helping, its working ! :) im using visual studio 2012 & opencv 2.4.13.

2017-05-14 11:56:48 -0600 commented question capture and save with 2 webcams C++

thanks for replying. im using 1,2 because i dont want my laptops webcam. i didnt really understand, i want to save one picture from each webcam, so what i should add to the code? thanks !

2017-05-14 08:39:47 -0600 asked a question capture and save with 2 webcams C++

what do i need to add to my code in order to take the second picture as well ? right now it works only with one webcam, but i can see both on my screen. Thanks !

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
    //initialize and allocate memory to load the video stream from camera 
    cv::VideoCapture camera0(2);
    cv::VideoCapture camera1(1);

    if( !camera0.isOpened() ) return 1;
    if( !camera1.isOpened() ) return 1;

    while(true) {
        //grab and retrieve each frames of the video sequentially 
        cv::Mat3b frame0;
        camera0 >> frame0;
        cv::Mat3b frame1;
        camera1 >> frame1;

        cv::imshow("Video0", frame0);
        cv::imshow("Video1", frame1);

        //wait for 40 milliseconds
        int c = cvWaitKey(40);

        //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27) 
        if(27 == char(c)) break;
    }

    // Get the frame
Mat save_img; camera0 >> save_img;
if(save_img.empty())
{
  std::cerr << "Something is wrong with the webcam, could not get frame." << std::endl;
}
// Save the frame into a file
imwrite("test1.jpg", save_img); // A JPG FILE IS BEING SAVED

    return 0;
}