I have made a gui actually with 2 buttons. The first shows the output of the webcam and the second takes a picture from it and saves it!
That's the code for the first:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void campic::on_pushButton_2_clicked()
{
cvNamedWindow( "Webcam", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateCameraCapture(0) ;
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Webcam", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Webcam" );
}
|
This button is capturing video from the webcam. It has 2 main problems:
a)It does closes only with the [ESC] button, if I close the window from the
X button it automatically reopens!
b)When I push again this button and there is already a live capture in progress then the program force-quits with the ERRORS:
1 2 3 4 5
|
HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Unable to stop the stream.: Device or resource busy
Unable to stop the stream.: Bad file descriptor
HIGHGUI ERROR: V4L: Pixel format of incoming image is unsupported by OpenCV
The program has unexpectedly finished.
|
My logic says that the problem is that there is an already running webcaming and so these errors exist. A solution coulb be to check if there is an already webcaming progress and if it is then do nothing!
That's the code for the second button:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void campic::on_pushButton_clicked()
{ char home[150]="/home/";
strcat(home,user); //user = USERNAME (getenv("USER"))
char other[60]="/.config/program/webcam.jpg";
strcat(home,other);
CvCapture *pCapturedImage = cvCreateCameraCapture(0);
// Get the frame
IplImage *pSaveImg = cvQueryFrame(pCapturedImage);
// Save the frame into a file
cvSaveImage(home ,pSaveImg);
}
|
The problem with this is that it saves the image very well but if I push the button again it probably lets the webcam busy and the program force quits. I mean when I open the program and push this button it successfully takes a pic of me, but when I push again the button fro another picture it force quits! I am sure that it goes out of the void function because i can do other things on the program when having already push the button 1 time! So, these are the errors if I try to get another picture from the webcam:
1 2 3 4 5 6 7 8
|
HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Unable to stop the stream.: Device or resource busy
Unable to stop the stream.: Bad file descriptor
HIGHGUI ERROR: V4L: Pixel format of incoming image is unsupported by OpenCV
OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat, file /home/alex/OpenCV-2.1.0/src/cxcore/cxarray.cpp, line 2376
terminate called after throwing an instance of 'cv::Exception'
what(): /home/alex/OpenCV-2.1.0/src/cxcore/cxarray.cpp:2376: error: (-27) NULL array pointer is passed in function cvGetMat
The program has unexpectedly finished.
|
There also seems to be a little problem with these two. For instance if I chose to take webcam output and while taking output then the program crashes as well... I think that at the beginning of any void function of the two existing must have a kind of check....