Beispiel #1
0
int main()
{
	VideoCapture cap(CAMERA_NUMBER); // open the default camera
	SafeQueue<cv::Mat> *VideoFrameQueue = new SafeQueue<cv::Mat>; //Initialize our frame queue.

	if (cap.isOpened()) //If we were able to open the camera stream
	{
		//namedWindow(WINDOW_NAME, CV_WINDOW_AUTOSIZE); //create a window to display stream

		Initialize(VideoFrameQueue);

		//While we're grabbing frames from the camera
		Mat currentFrame;
		while (cap.read(currentFrame))
		{
			if (currentFrame.data != NULL)
			{
				//If we're at the queue limit, wait until space frees up
				while (VideoFrameQueue->ptr().size() >= MAX_IMG_QUEUE_SIZE)
				{
					cout << "Images in video queue exceeded max size: " << MAX_IMG_QUEUE_SIZE << endl;
					Sleep(1000);
				}

				VideoFrameQueue->enqueue(currentFrame); //Add our video frame to the processing queue

				if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
				{
					Destroy();
					cvDestroyWindow(WINDOW_NAME.c_str());
					break;
				}
			}
			Sleep(500);
		}
	}
	else
	{
		cout << "Unable to open camera stream.";
	}
	return 0;
}