Canny边缘检测2
Wikipedia,自由的百科全书
(修订版本间差异)
13:43 2007年6月25日的修订版本 Shiqi Yu (Talk | 贡献) ← Previous diff |
09:52 2008年2月29日的修订版本 Eralvc (Talk | 贡献) Next diff → |
||
第 15行: | 第 15行: | ||
char wndname[] = "Edge"; | char wndname[] = "Edge"; | ||
char tbarname[] = "Threshold"; | char tbarname[] = "Threshold"; | ||
- | int edge_thresh = 1; | + | |
IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0; | IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0; | ||
第 26行: | 第 26行: | ||
// Run the edge detector on grayscale | // Run the edge detector on grayscale | ||
- | cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 3); | + | cvCanny(gray, edge, (float)h, (float)h*3, 3); |
cvZero( cedge ); | cvZero( cedge ); | ||
第 38行: | 第 38行: | ||
{ | { | ||
char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg"; | char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg"; | ||
- | + | int edge_thresh = 1; | |
if( (image = cvLoadImage( filename, 1)) == 0 ) | if( (image = cvLoadImage( filename, 1)) == 0 ) | ||
return -1; | return -1; |
09:52 2008年2月29日的修订版本
运行结果:
代码: <c>#ifdef _CH_
- pragma package <opencv>
- endif
- ifndef _EiC
- include "cv.h"
- include "highgui.h"
- endif
char wndname[] = "Edge"; char tbarname[] = "Threshold";
IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0;
// define a trackbar callback void on_trackbar(int h) {
cvSmooth( gray, edge, CV_BLUR, 3, 3, 0, 0 ); cvNot( gray, edge );
// Run the edge detector on grayscale cvCanny(gray, edge, (float)h, (float)h*3, 3); cvZero( cedge ); // copy edge points cvCopy( image, cedge, edge );
cvShowImage(wndname, cedge);
}
int main( int argc, char** argv ) {
char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg"; int edge_thresh = 1; if( (image = cvLoadImage( filename, 1)) == 0 ) return -1;
// Create the output image cedge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 3);
// Convert to grayscale gray = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1); edge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1); cvCvtColor(image, gray, CV_BGR2GRAY);
// Create a window cvNamedWindow(wndname, 1);
// create a toolbar cvCreateTrackbar(tbarname, wndname, &edge_thresh, 100, on_trackbar);
// Show the image on_trackbar(0);
// Wait for a key stroke; the same function arranges events processing cvWaitKey(0); cvReleaseImage(&image); cvReleaseImage(&gray); cvReleaseImage(&edge); cvDestroyWindow(wndname);
return 0;
}
- ifdef _EiC
main(1,"edge.c");
- endif
</c>