PageRenderTime 568ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/decoder2/warp.cpp

https://github.com/joshuaeckroth/SURV-I
C++ | 55 lines | 47 code | 6 blank | 2 comment | 6 complexity | d3e904b2ae68ec40aab266a9cee1fc17 MD5 | raw file
  1. // Usage: warp <image>
  2. //
  3. #include <cv.h>
  4. #include <highgui.h>
  5. int main(int argc, char** argv) {
  6. CvPoint2D32f srcQuad[4], dstQuad[4];
  7. CvMat* warp_matrix = cvCreateMat(3,3,CV_32FC1);
  8. IplImage *src, *dst;
  9. if( argc == 2 && ((src=cvLoadImage(argv[1],1)) != 0 )) {
  10. dst = cvCloneImage(src);
  11. dst->origin = src->origin;
  12. cvZero(dst);
  13. srcQuad[0].x = 852;
  14. srcQuad[0].y = 523;
  15. srcQuad[1].x = 852;
  16. srcQuad[1].y = 560;
  17. srcQuad[2].x = 925;
  18. srcQuad[2].y = 560;
  19. srcQuad[3].x = 925;
  20. srcQuad[3].y = 523;
  21. dstQuad[0].x = 1260;
  22. dstQuad[0].y = 1115;
  23. dstQuad[1].x = 1260;
  24. dstQuad[1].y = 1300;
  25. dstQuad[2].x = 1625;
  26. dstQuad[2].y = 1300;
  27. dstQuad[3].x = 1625;
  28. dstQuad[3].y = 1115;
  29. cvGetPerspectiveTransform(
  30. srcQuad,
  31. dstQuad,
  32. warp_matrix
  33. );
  34. for(int i = 0; i < 3; i++)
  35. {
  36. for(int j = 0; j < 3; j++)
  37. {
  38. printf("warp[%d][%d] = %f\n", i, j, cvmGet(warp_matrix, i, j));
  39. }
  40. }
  41. cvWarpPerspective( src, dst, warp_matrix );
  42. cvNamedWindow( "Perspective_Warp", 1 );
  43. cvShowImage( "Perspective_Warp", dst );
  44. cvWaitKey();
  45. }
  46. cvReleaseImage(&dst);
  47. cvReleaseMat(&warp_matrix);
  48. return 0;
  49. }