I start using the C++ interface for OpenCV, instead of the old highgui C functions. Here is an example to do real time video capture from the default webcam.
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
if (!cap.isOpened())
return -1;
namedWindow("camera",CV_WINDOW_AUTOSIZE);
while (true)
{
Mat frame;
cap >> frame;
imshow("camera", frame);
if (waitKey(10) >= 0)
break;
}
return 0;
}