?? disttrans.c
字號:
char wndname[] = "Distance transform";
char tbarname[] = "Threshold";
int edge_thresh = 1;
// Load the source image
IPLIMAGE image = load_iplimage( "y2k.bmp" );
// Create the output image
IPLIMAGE dist = cvCreateImage( cvSize( image -> width, image -> height ), IPL_DEPTH_32F, 1 );
IPLIMAGE dist8u1 = cvCreateImage( cvSize( image -> width, image -> height ), IPL_DEPTH_8U, 1 );
IPLIMAGE dist8u2 = cvCreateImage( cvSize( image -> width, image -> height ), IPL_DEPTH_8U, 1 );
IPLIMAGE dist8u = cvCreateImage( cvSize( image -> width, image -> height ), IPL_DEPTH_8U, 3 ); // Converted depth32f to depth8u
IPLIMAGE dist32s = cvCreateImage( cvSize( image -> width, image -> height ), IPL_DEPTH_32S, 1 );
// Convert to grayscale
IPLIMAGE gray = cvCreateImage( cvSize(image->width, image->height), IPL_DEPTH_8U, 1 );
IPLIMAGE edge = cvCreateImage( cvSize(image->width, image->height), IPL_DEPTH_8U, 1 ); // After Threshold
iplColorToGray( image, gray );
// define a trackbar callback
void on_trackbar( int h )
{
int j;
int distStep = dist -> widthStep / 4;
float* currPointer;
cvThreshold( gray, edge,
( float )( edge_thresh ),
( float )( edge_thresh ),
CV_THRESH_BINARY );
//Distance transform
cvDistTransform( edge, dist,
CV_DIST_L2,
CV_DIST_MASK_5,
NULL );
iplMultiplySFP( dist, dist, 5000.0 );
for( j = 0, currPointer = dist -> imageData; j < dist -> height; j++, currPointer += distStep )
{
cvbSqrt( ( float* )( currPointer ),
( float* )( currPointer ),
dist -> width );
}
cvConvertScale( dist, dist32s, 1.0, 0.5 );
iplAndS( dist32s, dist32s, 255 );
iplConvert( dist32s, dist8u1 );
iplMultiplyS( dist32s, dist32s, -1 );
iplAddS( dist32s, dist32s, 255 );
iplConvert( dist32s, dist8u2 );
cvCvtPlaneToPix( dist8u1, dist8u2, dist8u2, 0, dist8u );
show_iplimage( wndname, dist8u );
}
// Create a window
named_window( wndname, 0 );
// create a toolbar
create_trackbar( tbarname, wndname, &edge_thresh, 255, on_trackbar );
// Show the image
on_trackbar( 0 );
// Wait for a key stroke; the same function arranges events processing
wait_key( 0 );
cvReleaseImage( &image );
cvReleaseImage( &gray );
cvReleaseImage( &edge );
cvReleaseImage( &dist );
cvReleaseImage( &dist8u );
cvReleaseImage( &dist8u1 );
cvReleaseImage( &dist8u2 );
cvReleaseImage( &dist32s );
destroy_window( wndname );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -