?? contour.c
字號(hào):
/************************************************** * 輪廓檢測(cè) * 主要函數(shù): * cvFindContours * cvDrawContours **************************************************//*********************************************************************** * OpenCV example * Copyright (C) 2006 Shiqi Yu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***********************************************************************/#include "cv.h"#include "cxcore.h"#include "highgui.h"int main( int argc, char** argv ){ //聲明IplImage指針 IplImage* pImg = NULL; IplImage* pContourImg = NULL; CvMemStorage * storage = cvCreateMemStorage(0); CvSeq * contour = 0; int mode = CV_RETR_EXTERNAL; if( argc == 3) if(strcmp(argv[2], "all") == 0) mode = CV_RETR_CCOMP; //內(nèi)外輪廓都檢測(cè) //創(chuàng)建窗口 cvNamedWindow("src", 1); cvNamedWindow("contour",1); //載入圖像,強(qiáng)制轉(zhuǎn)化為Gray if( argc >= 2 && (pImg = cvLoadImage( argv[1], 0)) != 0 ) { cvShowImage( "src", pImg ); //為輪廓顯示圖像申請(qǐng)空間 //3通道圖像,以便用彩色顯示 pContourImg = cvCreateImage(cvGetSize(pImg), IPL_DEPTH_8U, 3); //copy source image and convert it to BGR image cvCvtColor(pImg, pContourImg, CV_GRAY2BGR); //查找contour cvFindContours( pImg, storage, &contour, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE); } else { //銷(xiāo)毀窗口 cvDestroyWindow( "src" ); cvDestroyWindow( "contour" ); cvReleaseMemStorage(&storage); return -1; } //將輪廓畫(huà)出 cvDrawContours(pContourImg, contour, CV_RGB(0,0,255), CV_RGB(255, 0, 0), 2, 2, 8); //顯示圖像 cvShowImage( "contour", pContourImg ); cvWaitKey(0); //銷(xiāo)毀窗口 cvDestroyWindow( "src" ); cvDestroyWindow( "contour" ); //釋放圖像 cvReleaseImage( &pImg ); cvReleaseImage( &pContourImg ); cvReleaseMemStorage(&storage); return 0;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -