Execution exiting after running the code.
I am try to run the code but msv execution is exiting and sometimes it shows breakpoint error. P.S. code is copied.
#include "stdafx.h"
#include "opencv/cvaux.h"
#include "opencv/highgui.h"
#include "opencv/cxcore.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
CvCapture* camera = cvCreateCameraCapture(-1); // Use the default camera
IplImage* frame = 0;
CvMemStorage* storage = cvCreateMemStorage(0); //needed for Hough circles
// capturing some extra frames seems to help stability
frame = cvQueryFrame(camera);
frame = cvQueryFrame(camera);
frame = cvQueryFrame(camera);
// with default driver, PSEye is 640 x 480
CvSize size = cvSize(640, 480);
IplImage * hsv_frame = cvCreateImage(size, IPL_DEPTH_8U, 3);
IplImage* thresholded = cvCreateImage(size, IPL_DEPTH_8U, 1);
IplImage* thresholded2 = cvCreateImage(size, IPL_DEPTH_8U, 1);
CvScalar hsv_min = cvScalar(0, 50, 170, 0);
CvScalar hsv_max = cvScalar(10, 180, 256, 0);
CvScalar hsv_min2 = cvScalar(170, 50, 170, 0);
CvScalar hsv_max2 = cvScalar(256, 180, 256, 0);
//do {
frame = cvQueryFrame(camera);
if (frame != NULL) {
printf("got frame\n\r");
// color detection using HSV
cvCvtColor(frame, hsv_frame, CV_BGR2HSV);
// to handle color wrap-around, two halves are detected and combined
cvInRangeS(hsv_frame, hsv_min, hsv_max, thresholded);
cvInRangeS(hsv_frame, hsv_min2, hsv_max2, thresholded2);
cvOr(thresholded, thresholded2, thresholded);
cvSaveImage("thresholded.jpg", thresholded);
// hough detector works better with some smoothing of the image
cvSmooth(thresholded, thresholded, CV_GAUSSIAN, 9, 9);
CvSeq* circles = cvHoughCircles(thresholded, storage, CV_HOUGH_GRADIENT, 2, thresholded->height / 4, 100, 40, 20, 200);
for (int i = 0; i < circles->total; i++)
{
float* p = (float*)cvGetSeqElem(circles, i);
printf("Ball! x=%f y=%f r=%f\n\r", p[0], p[1], p[2]);
cvCircle(frame, cvPoint(cvRound(p[0]), cvRound(p[1])),
3, CV_RGB(0, 255, 0), -1, 8, 0);
cvCircle(frame, cvPoint(cvRound(p[0]), cvRound(p[1])),
cvRound(p[2]), CV_RGB(255, 0, 0), 3, 8, 0);
}
cvSaveImage("frame.jpg", frame);
}
else {
printf("Null frame\n\r");
}
//} while (true);
cvReleaseCapture(&camera);
return 0;
}
and errors are..
The thread 0x1cbc has exited with code 0 (0x0).
The thread 0xe84 has exited with code 0 (0x0).
The thread 0x1ec4 has exited with code 0 (0x0).
The thread 0x1590 has exited with code 0 (0x0).
The thread 0x11f8 has exited with code 0 (0x0).
The thread 0x1e04 has exited with code 0 (0x0).
The thread 0x1404 has exited with code 0 (0x0).
The program '[32] Myhello2.exe' has exited with code 0 (0x0).
People should learn to read their own code ... it returns code 0. This is not an error but an identification you added for telling the code ran to the end. There is literally a
command at the end of your code. The number is just the thread identification on startup of all your executions.
Also please quit using the old C-api, and switch to the newer C++-interface. Again an example of simple copy paste problems ...
I find it a good idea to enclose the code in a
try...catch
block andcatch Exception& e
. That can save you some headaches in the long run.help me, how to fix it. it will be very thankfull.
There is NO error ... your code works perfectly...
but it is exiting in my pc. without opening windows and all.
That is quite simple, you are just savinf images, not showing them ... Do you see the output of the printf function in your console? Did you try executing it from console and not from your development area?
its showing only a console for only 5 secs and exits.
well that is because you run from your IDE. Please add the following line before the last return 0: system("pause");
now in console it's showing 'Null frame press any key to continue...' and than exits
Seriously you should really read your code... Null frame means that your frame = cvQueryFrame(camera); did not work...