I have been in contact with opencv for several years since 2011 and have been writing some small programs. I have used the manual to complete some tasks and have not studied the code in depth. Now I graduated from, but failed to enter the image processing industry for various reasons, so we are now re-learning opencv, including analyzing code, learning algorithms, and writing blogs from time to time. Please contact us.
Build Environment: vs2010 + cv1.0
The latest CV is 3.0 alpha, but the 1.0 structure is simple, the basic functions are still there, And I am familiar with the C language, so choose 1.0.
Download the 1.0 installation file from the official website. The system automatically installs the file to c: \ Program Files (x86). Go to the opencv directory and you will find a c: \ Program Files (x86) file) \ opencv \ _ make directory, which contains opencv. SLN file. This is very recognizable. open the file with vs2010. Because it is a 2008 project file, you need to convert it. Fortunately, no error is reported. directly generate the project and use the debug version, because the original version is release, one-step debugging is not possible.
After the project is generated, the lib and DLL files ending with D are displayed in the corresponding directory. Based on the Principle of opencv configuration in vs (there are many online files and I will not repeat them here). Now the environment is complete, as long as you create a new project and perform one-step debugging, you can observe the internal structure of the function step by step.
# Include <cv. h> # include For debugging, go to cvsmooth:
CV_IMPL voidcvSmooth( const void* srcarr, void* dstarr, int smooth_type, int param1, int param2, double param3, double param4 ){ CvBoxFilter box_filter; CvSepFilter gaussian_filter; CvMat* temp = 0; CV_FUNCNAME( "cvSmooth" ); __BEGIN__; int coi1 = 0, coi2 = 0; CvMat srcstub, *src = (CvMat*)srcarr; CvMat dststub, *dst = (CvMat*)dstarr; CvSize size; int src_type, dst_type, depth, cn; double sigma1 = 0, sigma2 = 0; bool have_ipp = icvFilterMedian_8u_C1R_p != 0; CV_CALL( src = cvGetMat( src, &srcstub, &coi1 )); CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 )); if( coi1 != 0 || coi2 != 0 ) CV_ERROR( CV_BadCOI, "" ); src_type = CV_MAT_TYPE( src->type ); dst_type = CV_MAT_TYPE( dst->type ); depth = CV_MAT_DEPTH(src_type); cn = CV_MAT_CN(src_type); size = cvGetMatSize(src); if( !CV_ARE_SIZES_EQ( src, dst )) CV_ERROR( CV_StsUnmatchedSizes, "" ); if( smooth_type != CV_BLUR_NO_SCALE && !CV_ARE_TYPES_EQ( src, dst )) CV_ERROR( CV_StsUnmatchedFormats, "The specified smoothing algorithm requires input and ouput arrays be of the same type" ); if( smooth_type == CV_BLUR || smooth_type == CV_BLUR_NO_SCALE || smooth_type == CV_GAUSSIAN || smooth_type == CV_MEDIAN ) { // automatic detection of kernel size from sigma if( smooth_type == CV_GAUSSIAN ) { sigma1 = param3; sigma2 = param4 ? param4 : param3; if( param1 == 0 && sigma1 > 0 ) param1 = cvRound(sigma1*(depth == CV_8U ? 3 : 4)*2 + 1)|1; if( param2 == 0 && sigma2 > 0 ) param2 = cvRound(sigma2*(depth == CV_8U ? 3 : 4)*2 + 1)|1; } if( param2 == 0 ) param2 = size.height == 1 ? 1 : param1; if( param1 < 1 || (param1 & 1) == 0 || param2 < 1 || (param2 & 1) == 0 ) CV_ERROR( CV_StsOutOfRange, "Both mask width and height must be >=1 and odd" ); if( param1 == 1 && param2 == 1 ) { cvConvert( src, dst ); EXIT; } } if( have_ipp && (smooth_type == CV_BLUR || smooth_type == CV_MEDIAN) && size.width >= param1 && size.height >= param2 && param1 > 1 && param2 > 1 ) { CvSmoothFixedIPPFunc ipp_median_box_func = 0; if( smooth_type == CV_BLUR ) { ipp_median_box_func = src_type == CV_8UC1 ? icvFilterBox_8u_C1R_p : src_type == CV_8UC3 ? icvFilterBox_8u_C3R_p : src_type == CV_8UC4 ? icvFilterBox_8u_C4R_p : src_type == CV_32FC1 ? icvFilterBox_32f_C1R_p : src_type == CV_32FC3 ? icvFilterBox_32f_C3R_p : src_type == CV_32FC4 ? icvFilterBox_32f_C4R_p : 0; } else if( smooth_type == CV_MEDIAN ) { ipp_median_box_func = src_type == CV_8UC1 ? icvFilterMedian_8u_C1R_p : src_type == CV_8UC3 ? icvFilterMedian_8u_C3R_p : src_type == CV_8UC4 ? icvFilterMedian_8u_C4R_p : 0; } if( ipp_median_box_func ) { CvSize el_size = { param1, param2 }; CvPoint el_anchor = { param1/2, param2/2 }; int stripe_size = 1 << 14; // the optimal value may depend on CPU cache, // overhead of the current IPP code etc. const uchar* shifted_ptr; int y, dy = 0; int temp_step, dst_step = dst->step; CV_CALL( temp = icvIPPFilterInit( src, stripe_size, el_size )); shifted_ptr = temp->data.ptr + el_anchor.y*temp->step + el_anchor.x*CV_ELEM_SIZE(src_type); temp_step = temp->step ? temp->step : CV_STUB_STEP; for( y = 0; y < src->rows; y += dy ) { dy = icvIPPFilterNextStripe( src, temp, y, el_size, el_anchor ); IPPI_CALL( ipp_median_box_func( shifted_ptr, temp_step, dst->data.ptr + y*dst_step, dst_step, cvSize(src->cols, dy), el_size, el_anchor )); } EXIT; } } if( smooth_type == CV_BLUR || smooth_type == CV_BLUR_NO_SCALE ) { CV_CALL( box_filter.init( src->cols, src_type, dst_type, smooth_type == CV_BLUR, cvSize(param1, param2) )); CV_CALL( box_filter.process( src, dst )); } else if( smooth_type == CV_MEDIAN ) { if( depth != CV_8U || cn != 1 && cn != 3 && cn != 4 ) CV_ERROR( CV_StsUnsupportedFormat, "Median filter only supports 8uC1, 8uC3 and 8uC4 images" ); IPPI_CALL( icvMedianBlur_8u_CnR( src->data.ptr, src->step, dst->data.ptr, dst->step, size, param1, cn )); } else if( smooth_type == CV_GAUSSIAN ) { CvSize ksize = { param1, param2 }; float* kx = (float*)cvStackAlloc( ksize.width*sizeof(kx[0]) ); float* ky = (float*)cvStackAlloc( ksize.height*sizeof(ky[0]) ); CvMat KX = cvMat( 1, ksize.width, CV_32F, kx ); CvMat KY = cvMat( 1, ksize.height, CV_32F, ky ); CvSepFilter::init_gaussian_kernel( &KX, sigma1 ); if( ksize.width != ksize.height || fabs(sigma1 - sigma2) > FLT_EPSILON ) CvSepFilter::init_gaussian_kernel( &KY, sigma2 ); else KY.data.fl = kx; if( have_ipp && size.width >= param1*3 && size.height >= param2 && param1 > 1 && param2 > 1 ) { int done; CV_CALL( done = icvIPPSepFilter( src, dst, &KX, &KY, cvPoint(ksize.width/2,ksize.height/2))); if( done ) EXIT; } CV_CALL( gaussian_filter.init( src->cols, src_type, dst_type, &KX, &KY )); CV_CALL( gaussian_filter.process( src, dst )); } else if( smooth_type == CV_BILATERAL ) { if( param1 < 0 || param2 < 0 ) CV_ERROR( CV_StsOutOfRange, "Thresholds in bilaral filtering should not bee negative" ); param1 += param1 == 0; param2 += param2 == 0; if( depth != CV_8U || cn != 1 && cn != 3 ) CV_ERROR( CV_StsUnsupportedFormat, "Bilateral filter only supports 8uC1 and 8uC3 images" ); IPPI_CALL( icvBilateralFiltering_8u_CnR( src->data.ptr, src->step, dst->data.ptr, dst->step, size, param1, param2, cn )); } __END__; cvReleaseMat( &temp );}
0th days of learning opencv