/opencv_extra/learning_opencv_v2/ch3_ex3_13.cpp

https://github.com/malcolmreynolds/OpenCV · C++ · 76 lines · 34 code · 11 blank · 31 comment · 4 complexity · 46791d82798d77a59f1c221cf3ed6129 MD5 · raw file

  1. /* License:
  2. Oct. 3, 2008
  3. Right to use this code in any way you want without warrenty, support or any guarentee of it working.
  4. BOOK: It would be nice if you cited it:
  5. Learning OpenCV: Computer Vision with the OpenCV Library
  6. by Gary Bradski and Adrian Kaehler
  7. Published by O'Reilly Media, October 3, 2008
  8. AVAILABLE AT:
  9. http://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134
  10. Or: http://oreilly.com/catalog/9780596516130/
  11. ISBN-10: 0596516134 or: ISBN-13: 978-0596516130
  12. OTHER OPENCV SITES:
  13. * The source code is on sourceforge at:
  14. http://sourceforge.net/projects/opencvlibrary/
  15. * The OpenCV wiki page (As of Oct 1, 2008 this is down for changing over servers, but should come back):
  16. http://opencvlibrary.sourceforge.net/
  17. * An active user group is at:
  18. http://tech.groups.yahoo.com/group/OpenCV/
  19. * The minutes of weekly OpenCV development meetings are at:
  20. http://pr.willowgarage.com/wiki/OpenCV
  21. */
  22. #include <cv.h>
  23. #include <highgui.h>
  24. // ch3_ex3_13 image_name x y width height add#
  25. int main(int argc, char** argv)
  26. {
  27. IplImage* interest_img;
  28. CvRect interest_rect;
  29. if( argc == 7 && ((interest_img=cvLoadImage(argv[1],1)) != 0 ))
  30. {
  31. interest_rect.x = atoi(argv[2]);
  32. interest_rect.y = atoi(argv[3]);
  33. interest_rect.width = atoi(argv[4]);
  34. interest_rect.height = atoi(argv[5]);
  35. int add = atoi(argv[6]);
  36. // Assuming IplImage *interest_img; and
  37. // CvRect interest_rect;
  38. // Use widthStep to get a region of interest
  39. //
  40. // (Alternate method)
  41. //
  42. IplImage *sub_img = cvCreateImageHeader(
  43. cvSize(
  44. interest_rect.width,
  45. interest_rect.height
  46. ),
  47. interest_img->depth,
  48. interest_img->nChannels
  49. );
  50. sub_img->origin = interest_img->origin;
  51. sub_img->widthStep = interest_img->widthStep;
  52. sub_img->imageData = interest_img->imageData +
  53. interest_rect.y * interest_img->widthStep +
  54. interest_rect.x * interest_img->nChannels;
  55. cvAddS( sub_img, cvScalar(add), sub_img );
  56. cvReleaseImageHeader(&sub_img);
  57. cvNamedWindow( "Roi_Add", CV_WINDOW_AUTOSIZE );
  58. cvShowImage( "Roi_Add", interest_img );
  59. cvWaitKey();
  60. }
  61. return 0;
  62. }