OpenCV + Command Line Interface

I am working in VS10.

I am working on building an interface for an arduino powered project I am working on. I am using the OpenCV library to capture a webcam stream and output it to the screen. This is done inside a while loop, so my program does nothing else while this is running. I want to be able to refresh the stream at around 30fps while also accepting input from std so that I can issue commands to the program. Will I need to look into threading? I have read that perhaps using a "windowstimer" would help me here but I haven't been able to find much information about how to implement that. Is there an easier way?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include "cv.h"
#include "highgui.h"

int _tmain(int argc, _TCHAR* argv[])
{
	CvCapture *capture = 0;
	IplImage  *frame = 0;
	int       key = 0;
	CvFont font;
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 1, CV_AA);
	/* initialize camera */
	capture = cvCaptureFromCAM(0);

	/* always check */
	if ( !capture ) {
		fprintf( stderr, "Cannot open initialize webcam!\n" );
		return 1;
	}

	//Set the resolution of the capture stream
	cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 640);
	cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 480);

	/* create a window for the video */
	cvNamedWindow( "Turret", CV_WINDOW_AUTOSIZE );

	while( key != 'q' ) {
		/* get a frame */
		frame = cvQueryFrame( capture );

		/* always check */
		if( !frame ) break;

		cvPutText(frame, "Turret cam", cvPoint(10, 130), &font, cvScalar(255, 255, 255, 0));

		/* display current frame */
		cvShowImage( "Turret", frame );

		/* exit if user press 'q' */
		key = cvWaitKey( 10 );
	}

	/* free memory */
	cvDestroyWindow( "result" );
	cvReleaseCapture( &capture );

	return 0;
}

Topic archived. No new replies allowed.