~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/copyMakeBorder_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
 * @file copyMakeBorder_demo.cpp
 
3
 * @brief Sample code that shows the functionality of copyMakeBorder
 
4
 * @author OpenCV team
 
5
 */
 
6
 
 
7
#include "opencv2/imgproc/imgproc.hpp"
 
8
#include "opencv2/imgcodecs.hpp"
 
9
#include "opencv2/highgui/highgui.hpp"
 
10
#include <stdlib.h>
 
11
#include <stdio.h>
 
12
 
 
13
using namespace cv;
 
14
 
 
15
/// Global Variables
 
16
Mat src, dst;
 
17
int top, bottom, left, right;
 
18
int borderType;
 
19
const char* window_name = "copyMakeBorder Demo";
 
20
RNG rng(12345);
 
21
 
 
22
/**
 
23
 * @function main
 
24
 */
 
25
int main( int, char** argv )
 
26
{
 
27
 
 
28
  int c;
 
29
 
 
30
  /// Load an image
 
31
  src = imread( argv[1] );
 
32
 
 
33
  if( src.empty() )
 
34
    {
 
35
      printf(" No data entered, please enter the path to an image file \n");
 
36
      return -1;
 
37
    }
 
38
 
 
39
  /// Brief how-to for this program
 
40
  printf( "\n \t copyMakeBorder Demo: \n" );
 
41
  printf( "\t -------------------- \n" );
 
42
  printf( " ** Press 'c' to set the border to a random constant value \n");
 
43
  printf( " ** Press 'r' to set the border to be replicated \n");
 
44
  printf( " ** Press 'ESC' to exit the program \n");
 
45
 
 
46
  /// Create window
 
47
  namedWindow( window_name, WINDOW_AUTOSIZE );
 
48
 
 
49
  /// Initialize arguments for the filter
 
50
  top = (int) (0.05*src.rows); bottom = (int) (0.05*src.rows);
 
51
  left = (int) (0.05*src.cols); right = (int) (0.05*src.cols);
 
52
  dst = src;
 
53
 
 
54
  imshow( window_name, dst );
 
55
 
 
56
  for(;;)
 
57
       {
 
58
         c = waitKey(500);
 
59
 
 
60
         if( (char)c == 27 )
 
61
           { break; }
 
62
         else if( (char)c == 'c' )
 
63
           { borderType = BORDER_CONSTANT; }
 
64
         else if( (char)c == 'r' )
 
65
           { borderType = BORDER_REPLICATE; }
 
66
 
 
67
         Scalar value( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) );
 
68
         copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );
 
69
 
 
70
         imshow( window_name, dst );
 
71
       }
 
72
 
 
73
  return 0;
 
74
}