void cv Accconst Cv Arr image Cv Arr























- Slides: 23
평균 배경 방법 �각 픽셀의 평균과 평균편차를 이용 � 간단하고 빠르지만 움직이는 배경요소에 약함 � 사용되는 주요 함수 ◦ void cv. Acc(const Cv. Arr* image, Cv. Arr* sum, const Cv. Arr* mask=NULL); ◦ void cv. Abs. Diff(const Cv. Arr* src 1, const Cv. Arr* src 2, Cv. Arr* dst); ◦ void cv. In. Range(const Cv. Arr* src, const Cv. Arr* lower, const Cv. Arr* upper, Cv. Arr* dst); ◦ void cv. Or(const Cv. Arr* src 1, const Cv. Arr* src 2, Cv. Arr* dst, const Cv. Arr* mask=NULL);
워터쉐드 알고리즘 //영상 불러오고 초기화 한 후 … cv. Set. Mouse. Callback( "image", on_mouse, 0 ); … int c = cv. Wait. Key(0); if( (char)c == 'w' || (char)c == ' ' ) { Cv. Mem. Storage* storage = cv. Create. Mem. Storage(0); Cv. Seq* contours = 0; Cv. Mat* color_tab; int i, j, comp_count = 0; cv. Find. Contours( marker_mask, storage, &contours, sizeof(Cv. Contour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); cv. Zero( markers ); for( ; contours != 0; contours = contours->h_next, comp_count++ ) { cv. Draw. Contours( markers, contours, cv. Scalar. All(comp_count+1), -1, 8, cv. Point(0, 0) ); } color_tab = cv. Create. Mat( 1, comp_count, CV_8 UC 3 ); for( i = 0; i < comp_count; i++ ) { uchar* ptr = color_tab->data. ptr + i*3; ptr[0] = (uchar)(cv. Rand. Int(&rng)%180 + 50); ptr[1] = (uchar)(cv. Rand. Int(&rng)%180 + 50); ptr[2] = (uchar)(cv. Rand. Int(&rng)%180 + 50); } { double t = (double)cv. Get. Tick. Count(); cv. Watershed( img 0, markers ); t = (double)cv. Get. Tick. Count() - t; printf( "exec time = %gmsn", t/(cv. Get. Tick. Frequency()*1000. ) ); } // paint the watershed image for( i = 0; i < markers->height; i++ ) for( j = 0; j < markers->width; j++ ) { int idx = CV_IMAGE_ELEM( markers, int, i, j ); uchar* dst = &CV_IMAGE_ELEM( wshed, uchar, i, j*3 ); if( idx == -1 ) dst[0] = dst[1] = dst[2] = (uchar)255; else if( idx <= 0 || idx > comp_count ) dst[0] = dst[1] = dst[2] = (uchar)0; // should not get here else { uchar* ptr = color_tab->data. ptr + (idx-1)*3; dst[0] = ptr[0]; dst[1] = ptr[1]; dst[2] = ptr[2]; } } } cv. Add. Weighted( wshed, 0. 5, img_gray, 0. 5, 0, wshed ); cv. Show. Image( "watershed transform", wshed ); cv. Release. Mem. Storage( &storage ); cv. Release. Mat( &color_tab );
인페인팅 //영상 불러오고 초기화 한 후 … cv. Set. Mouse. Callback( "image", on_mouse, 0 ); … int c = cv. Wait. Key(0); if( (char)c == 'i' || (char)c == ' ' ) { cv. Named. Window( "inpainted image", 1 ); cv. Inpaint( img, inpaint_mask, inpainted, 3, CV_INPAINT_TELEA ); } cv. Show. Image( "inpainted image", inpainted );