Program won't start when using OpenCV in C++ to stream video from camera
c++, camera, device, opencv, video-streaming
Solution
I suggest you to try this way of dealing with cameras, using the OpenCV 2.3.1.
VideoCapture _videoSource;
bool camera = 1;
if(camera)
{
if(!_videoSource.open(0)) // Try to start camera. 0 = default camera
{
cout << "Error opening camera" << endl; // here you control why the error happens
exit(1); // Exit if fail
}
}
else
{
if(!_videoSource.open(Path+"video.avi"))
{
cout << "Error opening file" << endl;
exit(2); // Exit if fail
}
}
_videoSource.set(CV_CAP_PROP_CONVERT_RGB, 1);
Mat frame;
namedWindow("Image");
while(1)
{
_videoSource >> frame;
imshow("output", frame);
return 0;
}
If this fails, the you will know for sure that the problem is with your camera. Maybe the drivers. Good luck.
Problem
right, I have a USB camera connected to the PC and I want to use OpenCV to stream images from it. Here is my code: ``` #include <cv.h> #include <highgui.h> #include <stdio.h> int main() { CvCapture* cameraCapture = cvCaptureFromCAM(CV_CAP_ANY); cvNamedWindow("Camera"); while(1) { IplImage* frame = cvQueryFrame(cameraCapture); cvShowImage("Camera", frame); if((cvWaitKey(10) & 255) == 27) break; } cvReleaseCapture(&cameraCapture); cvDestroyWindow("Camera"); } ``` The problem is that when I start the program I get this pop-up error: "The application was unable to start correctly (0xc0150002). Click OK to close the application". I have made sure I have included all the correct libraries, header files and ddl's so I'm really not sure whats wrong with it. Any help to solve this problem will be greatly appreciated.