?? laplace.c
字號:
/*程序名稱:laplace.c功能:從攝像頭或者AVI文件中得到視頻流,對視頻流進行邊緣檢測,并輸出結果。*/#include "cv.h"#include "highgui.h" #include <ctype.h>#include <stdio.h>
int main( int argc, char** argv ){ IplImage* laplace = 0; IplImage* colorlaplace = 0; IplImage* planes[3] = { 0, 0, 0 }; // 多個圖像面 CvCapture* capture = 0; // 下面的語句說明在命令行執行程序時,如果指定AVI文件,那么處理從 // AVI文件讀取的視頻流,如果不指定輸入變量,那么處理從攝像頭獲取 // 的視頻流if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 ); else if( argc == 2 ) capture = cvCaptureFromAVI( argv[1] ); if( !capture ) { fprintf(stderr,"Could not initialize capturing...\n"); return -1; } cvNamedWindow( "Laplacian", 0 ); // 循環捕捉,直到用戶按鍵跳出循環體 for(;;) { IplImage* frame = 0; int i; frame = cvQueryFrame( capture ); if( !frame ) break; if( !laplace ) { for( i = 0; i < 3; i++ ) planes[i] = cvCreateImage( cvSize(frame->width,frame->height), 8, 1 );laplace = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_16S, 1 ); colorlaplace = cvCreateImage( cvSize(frame->width,frame->height), 8, 3 ); } cvCvtPixToPlane( frame, planes[0], planes[1], planes[2], 0 ); for( i = 0; i < 3; i++ ) { cvLaplace( planes[i], laplace, 3 ); // 3: aperture_size cvConvertScaleAbs( laplace, planes[i], 1, 0 ); // planes[] = ABS(laplace) } cvCvtPlaneToPix( planes[0], planes[1], planes[2], 0, colorlaplace ); colorlaplace->origin = frame->origin; cvShowImage("Laplacian", colorlaplace ); if( cvWaitKey(10) >= 0 ) break; } cvReleaseCapture( &capture ); cvDestroyWindow("Laplacian"); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -