1 | initial version |
My solution was a little bit different:
// CameraFeed02e.cpp : Defines the entry point for the console application.
//
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
// Initialize and allocate memory to load the video stream from camera
VideoCapture camera(0);
if (!camera.isOpened())
return 1;
while (true)
{
// Grab and retrieve each frames of the video sequentially
Mat frame;
camera >> frame;
//imshow("VideoOriginal", frame); //just for debug purpose
// Set Region of Interest to the area defined by the box
cv::Rect roi;
roi.x = 0;
roi.y = 0;
roi.width = 320;
roi.height = 480;
// Crop the original image to the defined ROI
cv::Mat crop = frame(roi);
cv::imshow("crop", crop);
//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;
}
return 0;
}