/src/combine.cc

https://github.com/aldonline/node-nativeimage · C++ · 52 lines · 29 code · 11 blank · 12 comment · 0 complexity · b2074a1a0a2a5a21ed2ca9db496b2ff1 MD5 · raw file

  1. #include <opencv2/opencv.hpp>
  2. #include "combine.h"
  3. // http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port
  4. // http://togaen.wordpress.com/2011/08/04/xcode-and-opencv-2-via-macports/
  5. void combine4( char* path1, char* path2, char* path3, char* path4, char* dest_path ){
  6. // order in which they are combined:
  7. // 0 1
  8. // 2 3
  9. // load all images
  10. IplImage* img0 = cvLoadImage( path1 );
  11. IplImage* img1 = cvLoadImage( path2 );
  12. IplImage* img2 = cvLoadImage( path3 );
  13. IplImage* img3 = cvLoadImage( path4 );
  14. // if all images were added to a full-size montage
  15. // these would be the dimensions
  16. unsigned short w = img0->width + img1->width;
  17. unsigned short h = img0->height + img2->height;
  18. // create destination image, half the size of the full-size montage
  19. IplImage* img = cvCreateImage( cvSize(w/2, h/2), 8, 3 );
  20. // copy+resize each image onto destination
  21. IplROI roi0 = { 0, 0, 0, img0->width/2, img0->height/2 };
  22. img->roi = &roi0;
  23. cvResize( img0, img );
  24. IplROI roi1 = { 0, img0->width/2, 0, img1->width/2, img1->height/2 };
  25. img->roi = &roi1;
  26. cvResize( img1, img );
  27. IplROI roi2 = { 0, 0, img0->height/2, img2->width/2, img2->height/2 };
  28. img->roi = &roi2;
  29. cvResize( img2, img );
  30. IplROI roi3 = { 0, img0->width/2, img0->height/2, img3->width/2, img3->height/2 };
  31. img->roi = &roi3;
  32. cvResize( img3, img );
  33. // cleanup
  34. img->roi = NULL;
  35. cvReleaseImage(&img0);
  36. cvReleaseImage(&img1);
  37. cvReleaseImage(&img2);
  38. cvReleaseImage(&img3);
  39. // save result to disk
  40. cvSaveImage( dest_path, img );
  41. }