Hi,
I am a student in asia. Now I am doing a project in HCI(Human Interacion Computer). I meet a problem for this code, the following code that I can compile and pass. But, When I am running .exe, there is an error and I try to debug it shows :stack over" Can somebody help me, to find the problem?
Thanks!
By the way i use dev-c Ver4.9.9.2
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "math.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <sstream>
#include <time.h>
using namespace std;
int main()
{
int c = 0;
CvSeq* a = 0;
CvCapture* capture = cvCaptureFromCAM(0);
if(!cvQueryFrame(capture)){ cout<<"Video capture failed, please check the camera."<<endl;}
else{cout<<"Video camera capture status: OK"<<endl;};
CvSize sz=cvGetSize(cvQueryFrame(capture));
IplImage* src = cvCreateImage( sz, 8, 3 );
IplImage* YCC=cvCreateImage( sz, 8, 1);
IplImage* YCrCb=cvCreateImage( sz, 8, 3);
CvMemStorage* storage = cvCreateMemStorage(0);
CvMemStorage* areastorage = cvCreateMemStorage(0);
CvMemStorage* minStorage = cvCreateMemStorage(0);
CvMemStorage* dftStorage = cvCreateMemStorage(0);
CvSeq* contours = NULL;
cvNamedWindow( "src",1);
while(c!= 27)
{
IplImage* bg = cvCreateImage( sz, 8, 3);
uchar *data=(uchar *)YCC->imageData;
CvScalar w;
double Y,Cr,Cb;
cvRectangle( bg, cvPoint(0,0), cvPoint(bg->width,bg->height), CV_RGB( 255, 255, 255), -1, 8, 0 );
bg->origin = 1;
for(int b = 0; b< int(bg->width/10); b++)
{
cvLine( bg, cvPoint(b*20, 0), cvPoint(b*20, bg->height), CV_RGB( 200, 200, 200), 1, 8, 0 );
cvLine( bg, cvPoint(0, b*20), cvPoint(bg->width, b*20), CV_RGB( 200, 200, 200), 1, 8, 0 );
}
src = cvQueryFrame( capture);
cvCvtColor(src,YCrCb,CV_BGR2YCrCb);
for(int i=0; i<(src->height);i++)
for(int j=0;j<src->width;j++)
{
w = cvGet2D(YCrCb,i,j);
Y = w.val[0];
Cr= w.val[1];
Cb= w.val[2];
if ((Y>=60)&&(Y<=250)&&(Cr<210)&&(Cr>140)&&(Cb<130)&&(Cb>90))
{
data[i*(YCC->widthStep) + j*(YCC->nChannels) + 0 ]=255;
data[i*(YCC->widthStep) + j*(YCC->nChannels) + 1 ]=255;
data[i*(YCC->widthStep) + j*(YCC->nChannels) + 2 ]=255;
}
else
{
data[i*(YCC->widthStep) + j*(YCC->nChannels) + 0 ]=0;
data[i*(YCC->widthStep) + j*(YCC->nChannels) + 1 ]=0;
data[i*(YCC->widthStep) + j*(YCC->nChannels) + 2 ]=0;
}
}
}
cvThreshold(YCC, YCC ,50, 255, CV_THRESH_BINARY );
cvCvtColor(YCC, YCC, CV_YCrCbRGB);
cvCvtColor(YCC, gray, RGB2GRAY);
cvSmooth(gray, hsv_mask, CV_MEDIAN, 27, 0, 0, 0};
cvFindContours( YCC, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0,0) );
CvSeq* contours2 = NULL;
double result = 0, result2 = 0;
while(contours)
{
result = fabs( cvContourArea( contours, CV_WHOLE_SEQ ) );
if ( result > result2) {result2 = result; contours2 = contours;};
contours = contours->h_next;
}
if (contours2)
{
CvRect rect = cvBoundingRect( contours2, 0 );
cvRectangle( bg, cvPoint(rect.x, rect.y + rect.height), cvPoint(rect.x + rect.width, rect.y), CV_RGB(0, 0, 255), 1, 8, 0 );
int checkcxt = cvCheckContourConvexity( contours2 );
CvSeq* hull = cvConvexHull2( contours2, 0, CV_CLOCKWISE, 0 );
CvSeq* defect = cvConvexityDefects( contours2, hull, dftStorage );
if( defect->total >=40 ) {cout << " Closed Palm " << endl;}
else {cout << " Open Palm " << endl;}
cout << "defet: " << defect->total << endl;
CvBox2D box = cvMinAreaRect2( contours2, minStorage );
cvCircle( bg, cvPoint(box.center.x, box.center.y), 3, CV_RGB(200, 0, 200), 2, 8, 0 );
cvEllipse( bg, cvPoint(box.center.x, box.center.y), cvSize(box.size.height/2, box.size.width/2), box.angle, 0, 360, CV_RGB(220, 0, 220), 1, 8, 0 );
IplImage* contour = cvCreateImage( sz, 8, 3 );
cvDrawContours( bg, contours2, CV_RGB( 255, 0, 0), CV_RGB( 0, 0, 100), 1, 4, 8, cvPoint(0,0));
cvShowImage( "src", src)
cvNamedWindow("bg",0);
cvShowImage("bg",bg);
cvReleaseImage( &bg);
c = cvWaitKey( 1000);
}
cvReleaseCapture( &capture);
cvDestroyAllWindows();
}