




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、文檔供參考,可復(fù)制、編制,期待您的好評與關(guān)注! #include "cv.h"#include "highgui.h" #include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>#include <math.h>#include <float.h>#include <limits.h>#include <time.h>#include <ctype.h> #
2、ifdef _EiC#define WIN32#endif static CvMemStorage* storage = 0;static CvHaarClassifierCascade* cascade = 0; void detect_and_draw( IplImage* image ); const char* cascade_name = "haarcascade_frontalface_alt.xml"/* "haarcascade_profileface.xml"*/ int main( int argc, char* argv ) CvC
3、apture* capture = 0; IplImage *frame, *frame_copy = 0; int optlen = strlen("-cascade="); const char* input_name; if( argc > 1 && strncmp( argv1, "-cascade=", optlen ) = 0 ) cascade_name = argv1 + optlen; input_name = argc > 2 ? argv2 : 0; else cascade_name = ".
4、/./data/haarcascades/haarcascade_frontalface_alt2.xml" /opencv裝好后haarcascade_frontalface_alt2.xml的路徑, /也可以把這個文件拷到你的工程文件夾下然后不用寫路徑名cascade_name= "haarcascade_frontalface_alt2.xml" /或者cascade_name ="C:Program FilesOpenCVdatahaarcascadeshaarcascade_frontalface_alt2.xml" input_na
5、me = argc > 1 ? argv1 : 0; cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 ); if( !cascade ) fprintf( stderr, "ERROR: Could not load classifier cascaden" ); fprintf( stderr, "Usage: facedetect -cascade="<cascade_path>" filename|camera_indexn"
6、); return -1; storage = cvCreateMemStorage(0); if( !input_name | (isdigit(input_name0) && input_name1 = '0') ) capture = cvCaptureFromCAM( !input_name ? 0 : input_name0 - '0' ); else capture = cvCaptureFromAVI( input_name ); cvNamedWindow( "result", 1 ); if( capture
7、 ) for(;) if( !cvGrabFrame( capture ) break; frame = cvRetrieveFrame( capture ); if( !frame ) break; if( !frame_copy ) frame_copy = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels ); if( frame->origin = IPL_ORIGIN_TL ) cvCopy( frame, frame_copy, 0 ); els
8、e cvFlip( frame, frame_copy, 0 ); detect_and_draw( frame_copy ); if( cvWaitKey( 10 ) >= 0 ) break; cvReleaseImage( &frame_copy ); cvReleaseCapture( &capture ); else const char* filename = input_name ? input_name : (char*)"lena.jpg" IplImage* image = cvLoadImage( filename, 1 ); i
9、f( image ) detect_and_draw( image ); cvWaitKey(0); cvReleaseImage( &image ); else /* assume it is a text file containing the list of the image filenames to be processed - one per line */ FILE* f = fopen( filename, "rt" ); if( f ) char buf1000+1; while( fgets( buf, 1000, f ) ) int len =
10、 (int)strlen(buf); while( len > 0 && isspace(buflen-1) ) len-; buflen = '0' image = cvLoadImage( buf, 1 ); if( image ) detect_and_draw( image ); cvWaitKey(0); cvReleaseImage( &image ); fclose(f); cvDestroyWindow("result"); return 0; void detect_and_draw( IplImage* im
11、g ) static CvScalar colors = 0,0,255, 0,128,255, 0,255,255, 0,255,0, 255,128,0, 255,255,0, 255,0,0, 255,0,255 ; double scale = 1.3; IplImage* gray = cvCreateImage( cvSize(img->width,img->height), 8, 1 ); IplImage* small_img = cvCreateImage( cvSize( cvRound (img->width/scale), cvRound (img-&
12、gt;height/scale), 8, 1 ); int i; cvCvtColor( img, gray, CV_BGR2GRAY ); cvResize( gray, small_img, CV_INTER_LINEAR ); cvEqualizeHist( small_img, small_img ); cvClearMemStorage( storage ); if( cascade ) double t = (double)cvGetTickCount(); CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storag
13、e, 1.1, 2, 0/*CV_HAAR_DO_CANNY_PRUNING*/, cvSize(30, 30) ); t = (double)cvGetTickCount() - t; printf( "detection time = %gmsn", t/(double)cvGetTickFrequency()*1000.) ); for( i = 0; i < (faces ? faces->total : 0); i+ ) CvRect* r = (CvRect*)cvGetSeqElem( faces, i ); CvPoint center; int radius; center.x = cvRound(r->x + r->width*0.5)*scale); center.y = cvRound(r->y + r->height*0.5)*scale); radius
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 生態(tài)停車場車位代理銷售及維護(hù)管理合同
- 茶園場地承包與茶樹種植管理服務(wù)合同
- 柴油發(fā)電機(jī)組節(jié)能減排技術(shù)合作合同
- 商用車轉(zhuǎn)讓及運(yùn)營維護(hù)服務(wù)合同
- 茶樓與茶文化博物館合作合同
- 車輛運(yùn)輸合同爭議解決機(jī)制
- 菜鳥驛站快遞業(yè)務(wù)加盟合作合同
- 國際賽事參賽者出國擔(dān)保合同
- 和0有關(guān)的加減法教學(xué)課件
- 2025年農(nóng)業(yè)合作協(xié)議
- ?;愤\(yùn)輸安全責(zé)任劃分與追究的標(biāo)準(zhǔn)與程序
- 2024年江蘇省事業(yè)單位和國有企業(yè)招聘筆試參考題庫含答案解析
- 健康生活方式指導(dǎo)員培訓(xùn)
- 銷售團(tuán)隊管理課件
- 臨床路徑持續(xù)改進(jìn)QCC品管圈PDCA案例4例
- JGJT350-2015 保溫防火復(fù)合板應(yīng)用技術(shù)規(guī)程
- 基于SPWM變頻調(diào)速系統(tǒng)的畢業(yè)設(shè)計(帶仿真圖)
- 幼兒園大班數(shù)學(xué)活動《20以內(nèi)的數(shù)及加減法》
- 國家開放大學(xué)《理工英語4》機(jī)考參考答案(第1-3套)
- 項(xiàng)目延期申請表
- 體系文件編號規(guī)則
評論
0/150
提交評論