Hey guys!,
I’ve started working with OpenCV for a research project here at Georgia Tech. This was part of my initial tasks in week 1 of the project.
The code is quite self explanatory, do post questions if any.
!!! MAKE SURE YOU ADD THE PROPER STREAM ADDRESS IN THE CODE !!!
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2\opencv.hpp>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <string>
#include <Windows.h>
int main( int argc, const char** argv ) {
// Capture Object
VideoCapture vcap;
string address = ” “; //Enter stream address here
string location;
time_t start;
int interval = 0, j=0;
Mat image;
// Parameters to Save Image
vector compression_params; //vector that stores the compression parameters of the image
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); //specify the compression technique
compression_params.push_back(98); //specify the compression quality
cout << “Please wait until the camera opens…” <<endl;
if ( !vcap.open(address) ) {
cout << “\nUnable to access camera.” << endl;
return -1;
}
cout << interval;
cout << location;
start = time(NULL);
while(1) {
vcap.read(image);
if (interval != 0 && ((time(NULL)-start)%interval == 0) && start != time(NULL)) {
cout << ++j <<endl;
imshow(“Inteval Snap”, image);
waitKey(30);
start = time(NULL);
string op_file = location + to_string(j) + “.jpg”;
cout << op_file <<endl;
if(!imwrite(op_file,image,compression_params)) {
return -2;
}
waitKey(30);
}
}
vcap.release();
}
Cheers!
Sethu Chidambaram