在ycrvb颜色模型中使用opencv进行手检测 [英] hand detection using opencv in ycrvb color model

查看:114
本文介绍了在ycrvb颜色模型中使用opencv进行手检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是亚洲的学生.现在,我正在HCI(人机交互计算机)中做一个项目.我遇到了此代码的问题,可以编译并传递以下代码.但是,当我运行.exe时,出现错误,我尝试调试它显示:stack over有人可以帮助我,找到问题吗?
谢谢!

顺便说一下,我使用dev-c Ver4.9.9.2

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);
        /********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;
           }
           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;
	} 
	//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(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();
}

推荐答案

希望,不需要研究这个相当长的代码转储.另外,您的错误可能在其他地方.您报告的错误必须是堆栈溢出".这种错误很容易调查.

太糟糕了,您不能指示抛出异常的代码行.我从来不了解.您是否在调试器下运行代码?为什么?

递归相互递归永远不会结束的情况下,总是会发生这种情况,请参见 http://en.wikipedia.org/wiki/Recursion [^ ], http://en.wikipedia.org/wiki/Recursion_(computer_science) [ ^ ].

首先,您需要在调试器下运行代码,遇到异常并查看调用堆栈,以了解最近一次调用(位于当前堆栈顶部)的来源.注意重复调用具有相同功能或具有多个相同功能(或更多功能)的电话.

如果仍然看不到为什么递归从未结束,请尝试找到一个断点,该断点将在引发异常之前中断执行.一个好主意是将其放在重复调用的函数之一的开头.形成一个断点,逐步运行,直到遇到异常为止(比下一次记住这一点,并使用调试器的"Step into"(步入)而不是"Step over"),或者荒谬地找到导致无限调用的更深模式堆.该搜索将始终收敛于解决方案;并且很可能在调试模式下按照代码的所有细节之前就已经很好地解决了这个问题.

—SA
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 http://en.wikipedia.org/wiki/Recursion[^], http://en.wikipedia.org/wiki/Recursion_(computer_science)[^].

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.

—SA


****你! wat d hell代码有很多错误!任何1如何从其中创建.exe文件
**** u !! wat d hell code is ful of errors!! how can any 1 create .exe file out of it


这篇关于在ycrvb颜色模型中使用opencv进行手检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆