/opencv_extra/learning_opencv_v2/ch3_ex3_14.cpp

https://github.com/malcolmreynolds/OpenCV · C++ · 55 lines · 27 code · 2 blank · 26 comment · 6 complexity · 2db030b780daa4d3cf1ce60408f50a1d 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. // alphablend <imageA> <image B> <x> <y> <width> <height>
  23. // <alpha> <beta>
  24. #include <cv.h>
  25. #include <highgui.h>
  26. #include <stdio.h>
  27. int main(int argc, char** argv)
  28. {
  29. IplImage *src1, *src2;
  30. if( argc == 9 && ((src1=cvLoadImage(argv[1],1)) != 0
  31. )&&((src2=cvLoadImage(argv[2],1)) != 0 ))
  32. {
  33. int x = atoi(argv[3]);
  34. int y = atoi(argv[4]);
  35. int width = atoi(argv[5]);
  36. int height = atoi(argv[6]);
  37. double alpha = (double)atof(argv[7]);
  38. double beta = (double)atof(argv[8]);
  39. cvSetImageROI(src1, cvRect(x,y,width,height));
  40. cvSetImageROI(src2, cvRect(0,0,width,height));
  41. cvAddWeighted(src1, alpha, src2, beta,0.0,src1);
  42. cvResetImageROI(src1);
  43. cvNamedWindow( "Alpha_blend", 1 );
  44. cvShowImage( "Alpha_blend", src1 );
  45. cvWaitKey();
  46. }
  47. else
  48. printf("Couldn't load one or both of %s, %s\n",argv[1],argv[2]);
  49. return 0;
  50. }