Click here to Skip to main content
11,933,037 members (59,584 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++

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?

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);
        /********skin detec****************/ 
        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;
              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;
            result = fabs( cvContourArea( contours, CV_WHOLE_SEQ ) );
	    if ( result > result2) {result2 = result; contours2 = contours;};
	    contours  =  contours->h_next;
	//gesture recognition 
         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(,, 3, CV_RGB(200, 0, 200), 2, 8, 0 );	
	cvEllipse( bg, cvPoint(,, 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)
	cvReleaseImage( &bg);
	c = cvWaitKey( 1000);
	cvReleaseCapture( &capture);
Posted 14-Dec-10 0:25am
Edited 14-Dec-10 0:30am
JF2015 14-Dec-10 5:30am
Edited to correct code formatting.
CPallini 14-Dec-10 6:49am
Please report the exact error message and, above all, have a look at the debugger window named 'call stack' (on Visual Studio) where you may find useful info.
Dave Kreskowiak 14-Dec-10 11:01am
You're going to have to point out the line that throws the error. A StackOverflow usually means code is constantly calling itself, but never returns to the caller, therefore running the Stack out of space.
thatraja 26-Dec-10 2:58am
Include the error message in your question
aslican1988 7-Jul-11 15:51pm
YCrCb color space Real Time Hand Posture/Gesture Recognition with OpenCV
TRK3 7-Jul-11 15:58pm
Very cool!
SAKryukov 7-Jul-11 17:31pm
Great thing! Who is the author of this stuff, do you know?
SAKryukov 7-Jul-11 16:06pm
"Stack over"?! "Game overflow"!
harish85 7-Jul-11 16:32pm
I am just curious ,what do you do in this program?.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hopefully, there is not need to look at this pretty long code dump. Also, your bug can be somewhere else. The error you are reporting must be "Stack overflow". This kind of error is pretty easy to investigate.

Too bad you don't indicate the line of code where the exception is thrown. I never understood it. Do you run the code not under debugger? Why?

It always happen in the case of recursion or mutual recursion which never ends, see[^],[^].

First, you need to run the code under debugger, run into exception and look at the call stack to get an idea where the most recent call (on the top of current stack) come from. Pay attention for repeating calls the the same functions or a couple of the same functions (or more).

If you still don't see why recursion is never ended, try to find a place for a break point which would break execution before exception is thrown. A good idea is to put it at the beginning of one of the function which is called repeatedly. Form a break point, run step by step until you run into exception (than next time remember this point and use debugger's "Step into" instead of "Step over") or find a pattern absurdly leading to infinite calls deeper into the stack. This search will always converge to a solution; and very likely you will figure the problem well before you follow all the detail of the code in debug mode.

Espen Harlinn 7-Jul-11 16:40pm
Good points, my 5 - If he is building OpenCV from source - he can get Visual Studio to break off execution when the stack is overrun. The call stack should provide valuable information.
SAKryukov 7-Jul-11 16:49pm
Thank you, Espen.
TRK3 7-Jul-11 16:52pm
See OP's comment in the original thread. Original post was back in December. With no help or solution then. Today OP added a comment with a link:

Which appears to be a video of the completed project in action. So I guess OP already solved the stack overflow problem and was just updating us with a video showing the solution. Check it out. Quite cool.
SAKryukov 7-Jul-11 17:30pm
Sorry, you messed up. This link is not by OP. OP is "the_same", this person is not the same (pun intended) :-)

OP did not report that the problem is solved.
I think my answer is adequate and useful.

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

**** u !! wat d hell code is ful of errors!! how can any 1 create .exe file out of it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 1 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100