~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @function Geometric_Transforms_Demo.cpp
 
3
 * @brief Demo code for Geometric Transforms
 
4
 * @author OpenCV team
 
5
 */
 
6
 
 
7
#include "opencv2/imgcodecs.hpp"
 
8
#include "opencv2/highgui/highgui.hpp"
 
9
#include "opencv2/imgproc/imgproc.hpp"
 
10
#include <iostream>
 
11
#include <stdio.h>
 
12
 
 
13
using namespace cv;
 
14
using namespace std;
 
15
 
 
16
/// Global variables
 
17
const char* source_window = "Source image";
 
18
const char* warp_window = "Warp";
 
19
const char* warp_rotate_window = "Warp + Rotate";
 
20
 
 
21
/**
 
22
 * @function main
 
23
 */
 
24
int main( int, char** argv )
 
25
{
 
26
  Point2f srcTri[3];
 
27
  Point2f dstTri[3];
 
28
 
 
29
  Mat rot_mat( 2, 3, CV_32FC1 );
 
30
  Mat warp_mat( 2, 3, CV_32FC1 );
 
31
  Mat src, warp_dst, warp_rotate_dst;
 
32
 
 
33
  /// Load the image
 
34
  src = imread( argv[1], 1 );
 
35
 
 
36
  /// Set the dst image the same type and size as src
 
37
  warp_dst = Mat::zeros( src.rows, src.cols, src.type() );
 
38
 
 
39
  /// Set your 3 points to calculate the  Affine Transform
 
40
  srcTri[0] = Point2f( 0,0 );
 
41
  srcTri[1] = Point2f( src.cols - 1.f, 0 );
 
42
  srcTri[2] = Point2f( 0, src.rows - 1.f );
 
43
 
 
44
  dstTri[0] = Point2f( src.cols*0.0f, src.rows*0.33f );
 
45
  dstTri[1] = Point2f( src.cols*0.85f, src.rows*0.25f );
 
46
  dstTri[2] = Point2f( src.cols*0.15f, src.rows*0.7f );
 
47
 
 
48
  /// Get the Affine Transform
 
49
  warp_mat = getAffineTransform( srcTri, dstTri );
 
50
 
 
51
  /// Apply the Affine Transform just found to the src image
 
52
  warpAffine( src, warp_dst, warp_mat, warp_dst.size() );
 
53
 
 
54
  /** Rotating the image after Warp */
 
55
 
 
56
  /// Compute a rotation matrix with respect to the center of the image
 
57
  Point center = Point( warp_dst.cols/2, warp_dst.rows/2 );
 
58
  double angle = -50.0;
 
59
  double scale = 0.6;
 
60
 
 
61
  /// Get the rotation matrix with the specifications above
 
62
  rot_mat = getRotationMatrix2D( center, angle, scale );
 
63
 
 
64
  /// Rotate the warped image
 
65
  warpAffine( warp_dst, warp_rotate_dst, rot_mat, warp_dst.size() );
 
66
 
 
67
 
 
68
  /// Show what you got
 
69
  namedWindow( source_window, WINDOW_AUTOSIZE );
 
70
  imshow( source_window, src );
 
71
 
 
72
  namedWindow( warp_window, WINDOW_AUTOSIZE );
 
73
  imshow( warp_window, warp_dst );
 
74
 
 
75
  namedWindow( warp_rotate_window, WINDOW_AUTOSIZE );
 
76
  imshow( warp_rotate_window, warp_rotate_dst );
 
77
 
 
78
  /// Wait until user exits the program
 
79
  waitKey(0);
 
80
 
 
81
  return 0;
 
82
}