⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opencv_dialogdlg.cpp

📁 circle detecting source code
💻 CPP
字号:
// OpenCV_dialogDlg.cpp : implementation file
//
//  OpenCV 狼 cvcam 阑 捞侩窍咯 墨皋扼甫 涝仿 罐篮 康惑阑 Dialog 俊 焊咯林绰 家胶内靛 涝聪促.
//  磊技茄 汲疙捞唱 扁鸥 巩狼荤亲篮 酒贰 荤捞飘甫 规巩秦 林技夸.
//
//  - 2005. 11. 21. Dong-Chul Kim
//    http://www.opencv.co.kr
//    http://www.t9t9.com

#include "stdafx.h"
#include "OpenCV_dialog.h"
#include "OpenCV_dialogDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


#define FUN		1

bool m_bCamStart = false;		// 姆 矫累 咯何
int m_Mode = 0;					// 贸府 葛靛

CvFont* font = 0;
static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;
void callback(IplImage* image);
const char* cascade_name = "haarcascade_frontalface_alt.xml";
IplImage *frame,*frame_three, *frame_copy = 0;
  CvCapture* capture = 0;

/////////////////////////////////////////////////////////////////////////////
// COpenCV_dialogDlg dialog

COpenCV_dialogDlg::COpenCV_dialogDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COpenCV_dialogDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COpenCV_dialogDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void COpenCV_dialogDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COpenCV_dialogDlg)
	DDX_Control(pDX, IDC_BUTTON_THRESHOLD, m_BtnThreshold);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(COpenCV_dialogDlg, CDialog)
	//{{AFX_MSG_MAP(COpenCV_dialogDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_BUTTON_THRESHOLD, OnButtonThreshold)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COpenCV_dialogDlg message handlers

BOOL COpenCV_dialogDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	int nselected = cvcamGetCamerasCount(); 
	cvcamSetProperty(0, CVCAM_PROP_ENABLE, &nselected);

	m_ButtonWidth = 120;
	m_Width = 352,
	m_Height = 288;

	cvcamSetProperty(0, CVCAM_PROP_WINDOW, &(this->m_hWnd)); 
	cvcamSetProperty(0, CVCAM_RNDWIDTH, &m_Width);		// 墨皋扼 涝仿 荤捞令 呈厚
	cvcamSetProperty(0, CVCAM_RNDHEIGHT, &m_Height);		// 墨皋扼 涝仿 荤捞令 臭捞
	storage = cvCreateMemStorage(0);
 cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );

	cvcamSetProperty(0, CVCAM_PROP_CALLBACK, callback);	// frame 付促 龋免瞪 窃荐
	
	cvcamInit( );
	cvcamStart( );	

	MoveWindow( 0, 0, m_Width + m_ButtonWidth, m_Height+24, true );

	m_bCamStart = true;
	m_BtnThreshold.MoveWindow(m_Width + 10, 10, 100, 25, true);
//	cvNamedWindow( "sss", 1 );
//		cvNamedWindow( "ssss", 1 );
//		cvNamedWindow( "sssss", 1 );
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void COpenCV_dialogDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR COpenCV_dialogDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

BOOL COpenCV_dialogDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class

	// 扩档快啊 辆丰 瞪锭 墨皋扼档 辆丰
	cvcamStop( );
	cvcamExit( );
	
	return CDialog::DestroyWindow();
}

void COpenCV_dialogDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);

	m_Width = cx-m_ButtonWidth;
	m_Height = cy;
	
	// TODO: Add your message handler code here
	if(m_bCamStart){
		cvcamSetProperty(0, CVCAM_RNDWIDTH, &m_Width);
		cvcamSetProperty(0, CVCAM_RNDHEIGHT, &m_Height);

		m_BtnThreshold.MoveWindow(m_Width + 10, 10, 100, 25, true);

	}
}



void callback(IplImage* img)
{		
	


           IplImage* grayCircles = cvCreateImage( cvGetSize(img), 8, 1 );
           IplImage* grayCircles2 = cvCreateImage( cvGetSize(img), 8, 1 );
           CvMemStorage* storage = cvCreateMemStorage(0);
 // cvInRangeS(grayCircles,cvScalar(240,240,240),cvScalar(255,255,255),grayCircles);
          cvCvtColor( img, grayCircles, CV_BGR2GRAY );
          //cvInRangeS. It takes 4 parameters: an input images,
		  //a lower value, an upper value, and an output (mask) image.
          
		  cvSmooth(grayCircles, grayCircles, CV_GAUSSIAN, 9, 9); 
  
//cCvScalar::new_object(cvScalar(0xff,0xff,0xff))-white cCvScalar::new_object(cvScalar(0x0,0x80,0x0))Green

            //cvScalar(255, 255, 255)
       
         // cvInRangeS(grayCircles,cvScalar(0xff,0xff,0xff),cvScalar(0x0,0x80,0x0),grayCircles);
          CvSeq* circles = cvHoughCircles( grayCircles, 
                                                                 storage,
                                                                 CV_HOUGH_GRADIENT, 
                                                                 2, 
                                                                 grayCircles->height/4, 
                                                                50, 50, 0, 15 );
		  /////
   /* dp = 1
    param1=70
    param2=12
    min_dist = maxcircle
    min_radius=mincircle
    max_radius=maxcircle
    circles = cvHoughCircles(grayimg, storage, CV_HOUGH_GRADIENT, dp,
                     min_dist, param1, param2,
                     min_radius, max_radius)

*/


		  //////

  int i;   
  for (i = 0; i < circles->total; i++) 
  {
	  float* p = (float*)cvGetSeqElem( circles, i ); 
	  cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])),
		  3, CV_RGB(0,255,0), -1, 8, 0 );    
	  cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])),  
		  cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );    
  }    
  //cvNamedWindow( "circles", 1 ); 
  //cvShowImage( "circles", img );  
  cvWaitKey(0);    
  //return 0;



           cvReleaseMemStorage( &storage );
           cvReleaseImage( &grayCircles );
	
	
/*	IplImage *kkk=0;
			int i;
//			int j;
			CvPoint pt1, pt2;
			int scale = 1;

   
			if( !frame_copy )
				frame_copy = cvCreateImage( cvSize(img->width,img->height),

														IPL_DEPTH_8U, img->nChannels );
                    //cvCopy(img,frame_copy);
					//frame_copy->origin=img->origin;
			cvFlip(img,frame_copy);
				


		 
 if( cascade )
    {
        CvSeq* faces = cvHaarDetectObjects( frame_copy, cascade,storage,
                                            1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
                                            cvSize(40, 40) );
		       
			for( i = 0; i < (faces ? faces->total : 0); i++ )
				{
					CvRect* r = (CvRect*)cvGetSeqElem( faces, i );  //倔奔俊 荤阿屈 弊妨林扁 备泅
					pt1.x = r->x*scale;
					pt2.x = (r->x+r->width)*scale;
					pt1.y = r->y*scale;
					pt2.y = (r->y+r->height)*scale;
					cvRectangle( frame_copy, pt1, pt2, CV_RGB(255,255,0), 3, 8, 0 );
					cvFlip(img,img);
					cvRectangle( img, pt1, pt2, CV_RGB(255,255,0), 3, 8, 0 );
					cvFlip(img,img);
				}
			}*/
//if( cvWaitKey(30 ) >= 0 );

		//	cvShowImage("sss",frame_copy);
		//	cvShowImage("ssss",frame_copy);
		//	cvShowImage("sssss",frame_copy);


			
}

void COpenCV_dialogDlg::OnButtonThreshold() 
{
	// TODO: Add your control notification handler code here
	if(	m_Mode == FUN )
		m_Mode = 0;
	else
		m_Mode = FUN;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -