I'm attempting to capture a single frame from several USB cameras connected to a USB hub. I've written something which I believe should work, but it doesn't :(. The final result produces the correct number of images based on the argument, but all except the final are "blank".
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
#include <iostream>
using namespace cv;
int main(int argc, char** argv){
int numberOfCameras = atoi(argv[1]);
std::vector<Mat> frames (numberOfCameras-1);
for(int i=0; i<numberOfCameras; i++){
VideoCapture cap(i);
cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
Mat frame; cap >> frame;
frames.push_back(frame);
}
for(int i=0; i<numberOfCameras; i++){
string fileName = std::to_string(i) + ".jpg";
std::cout << fileName << std::endl;
imwrite(fileName, frames[i]);
}
}
What's going on here? I'm kinda new to C++ and typed languages in general. Am I misunderstanding the use of a vector? Is the above the best method of accomplishing my task?
I'll be connecting several more cameras (a total of 50) and am curious as to the repercussions of storing 50 frames in memory. Can I even open call capture on that many cameras?