Ask Your Question
-1

Program execution switches automatically off when using video capture.

asked 2013-08-12 08:25:45 -0600

Dejan gravatar image

updated 2013-08-12 09:05:52 -0600

I am using OpenCV 2.4.6 with Visual Studio 2010. I have a problem in video capturing.

The program has no errors and no warnings when building the solution. When I start debugging the program, it starts executing, switches camera on and then automatically off, and finally closes down command prompt. I am not getting any results back. But image processing and other program execution is ok.

Can anyone help me about it?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-08-12 09:09:43 -0600

What probably is happing is that your processing doesn't take that much time, processing happens and then your debugger gets to the end of your program. What you can do to see if anything goes wrong is adding the following code to your project.

// If you have no namedWindow defined yet, make a dummy at the end of your code, else ignore the first line
// It makes sure that the waitKey() event works.
namedWindow("dummy");
// Wait untill a key is pressed
waitKey(0);

This will keep your program and command prompt open until you hit enter. It is typical for VS to close down a window in debug mode, the moment you reach the end of your code and you have return 0. What you can also do is add a breakpoint before debugging, just at the return line. This will do the same in debug as the above code.

edit flag offensive delete link more

Comments

The program is about virtual mouse control. I am using the source code from the link below. Please check it and reply, where is the actual fault?

https://github.com/wncc-itsp-2013/p1w13-virtual-mouse-using-hand-gesture

Dejan gravatar imageDejan ( 2013-08-12 13:06:11 -0600 )edit

? wut ? Did you even try my suggestion? Also you just admitted using someone elses code, then wanting us to solve your problems? This is not going to happen ... read the FAQ to understand why we do not help out with these kind of problems...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-12 14:27:08 -0600 )edit

Dear StevenPuttemans, thanks for your comment. Sorry for sharing another person's source code. I have some source code that size are bigger than 800 characters. In your site, 800 characters limitation for a comment. I couldn't submit my source code in the comment. For that why, I shared this code. Again sorry for that.

Dejan gravatar imageDejan ( 2013-08-14 13:27:14 -0600 )edit

Dear StevenPuttemans, I have found the errors of video capture. I have used the code below: CvCapture* capture = cvCaptureFromCAM(0);
if(!cvQueryFrame(capture)) { cout<<"Video capture failed, please check the camera."<<endl; } else { cout<<"Video camera capture status: OK"<<endl; }

After execute the code, my webcam is open but i get the first error message "Video capture failed, please check the camera" that means webcam is not working. But my webcam is open and i get the video. Where is the problem? How can I solve it? Please help me.

Notice: I am using Laptop webcam, OpenCV 2.4.6 with Visual Studio 2010.

Dejan gravatar imageDejan ( 2013-08-14 14:22:10 -0600 )edit

Switch to C++ and the VideoCapture interface, and leave the old C style API behind. Showing larger codes can be done with a pastebin link.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-14 14:36:15 -0600 )edit

Thanks a lot for your help. I am trying to execute new C++ code for video capture. But its not working well. No build solution error. program execution is ok and webcam is also open. But I am getting errors below:

Command Prompt Showing Message: OpenCV Error: Assertion Failed (scn == 3 || scn == 4) is unknown function, file......\imgproc\src\color.cpp

Another Message box Came showing message:

Unhandled exception at 0x7681b727 in cv.exe: Microsoft C++ exception: cv::Exception at memory location 0x003bb414..

Dejan gravatar imageDejan ( 2013-08-14 15:49:55 -0600 )edit

It has something to do with you processing your input. Please edit your original question with the code.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-14 16:48:19 -0600 )edit

Dear StevenPuttemans, I am trying to execute below example. But after execution, it has generated some problems that I mentioned in above comment. Please give a solution aobut it.

include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**) { VideoCapture cap(0); if(!cap.isOpened()) return -1;

Mat edges;
namedWindow("edges",1);
for(;;)
{
    Mat frame;
    cap &gt;&gt; frame; 
    cvtColor(frame, edges, CV_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);
    if(waitKey(30) &gt;= 0) break;
}
return 0;

}

Dejan gravatar imageDejan ( 2013-08-15 14:17:57 -0600 )edit

It is GaussianBlur or Canny that generates the mistake. Output and input data cannot be the same Mat element :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-15 15:05:07 -0600 )edit

Question Tools

Stats

Asked: 2013-08-12 08:25:45 -0600

Seen: 656 times

Last updated: Aug 12 '13