PageRenderTime 30ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/opencv/src/edge.c

https://gitlab.com/juan-cardelino/misc_projects
C | 70 lines | 43 code | 18 blank | 9 comment | 3 complexity | 5510ccfa035df977b906ddea0aba330d MD5 | raw file
  1. #ifdef _CH_
  2. #pragma package <opencv>
  3. #endif
  4. #define CV_NO_BACKWARD_COMPATIBILITY
  5. #ifndef _EiC
  6. #include "cv.h"
  7. #include "highgui.h"
  8. #endif
  9. char wndname[] = "Edge";
  10. char tbarname[] = "Threshold";
  11. int edge_thresh = 1;
  12. IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0;
  13. // define a trackbar callback
  14. void on_trackbar(int h)
  15. {
  16. cvSmooth( gray, edge, CV_BLUR, 3, 3, 0, 0 );
  17. cvNot( gray, edge );
  18. // Run the edge detector on grayscale
  19. cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 3);
  20. cvZero( cedge );
  21. // copy edge points
  22. cvCopy( image, cedge, edge );
  23. cvShowImage(wndname, cedge);
  24. }
  25. int main( int argc, char** argv )
  26. {
  27. char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
  28. if( (image = cvLoadImage( filename, 1)) == 0 )
  29. return -1;
  30. // Create the output image
  31. cedge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 3);
  32. // Convert to grayscale
  33. gray = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
  34. edge = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 1);
  35. cvCvtColor(image, gray, CV_BGR2GRAY);
  36. // Create a window
  37. cvNamedWindow(wndname, 1);
  38. // create a toolbar
  39. cvCreateTrackbar(tbarname, wndname, &edge_thresh, 100, on_trackbar);
  40. // Show the image
  41. on_trackbar(0);
  42. // Wait for a key stroke; the same function arranges events processing
  43. cvWaitKey(0);
  44. cvReleaseImage(&image);
  45. cvReleaseImage(&gray);
  46. cvReleaseImage(&edge);
  47. cvDestroyWindow(wndname);
  48. return 0;
  49. }
  50. #ifdef _EiC
  51. main(1,"edge.c");
  52. #endif