minipix_uart_interface
A library and examples for the MiniPIX UART interface
opencv_helpers.hpp
Go to the documentation of this file.
1 #include <opencv2/opencv.hpp>
2 
3 #include <stdio.h>
4 #include <stdarg.h>
5 
6 using namespace cv;
7 using namespace std;
8 
9 /*
10 Function///////////////////////////////////////////////////////////////
11 
12 Name: ShowManyImages
13 
14 Purpose:
15 
16 This is a function illustrating how to display more than one
17 image in a single window using Intel OpenCV
18 
19 Parameters:
20 
21 string title: Title of the window to be displayed
22 int n_images: Number of images to be displayed
23 Mat img1: First Mat, which contains the first image
24 ...
25 Mat imgN: First Mat, which contains the Nth image
26 
27 Language: C++
28 
29 The method used is to set the ROIs of a Single Big image and then resizing
30 and copying the input images on to the Single Big Image.
31 
32 This function does not stretch the image...
33 It resizes the image without modifying the width/height ratio..
34 
35 This function can be called like this:
36 
37 ShowManyImages("Images", 5, img2, img2, img3, img4, img5);
38 
39 This function can display upto 12 images in a single window.
40 It does not check whether the arguments are of type Mat or not.
41 The maximum window size is 700 by 660 pixels.
42 Does not display anything if the number of arguments is less than
43 one or greater than 12.
44 
45 Idea was from [[BettySanchi]] of OpenCV Yahoo! Groups.
46 
47 If you have trouble compiling and/or executing
48 this code, I would like to hear about it.
49 
50 You could try posting on the OpenCV Yahoo! Groups
51 [url]http://groups.yahoo.com/group/OpenCV/messages/ [/url]
52 
53 
54 Parameswaran,
55 Chennai, India.
56 
57 cegparamesh[at]gmail[dot]com
58 
59 ...
61 */
62 
63 template <int PixelFormat>
64 void showManyImages(const string &title, const std::vector<cv::Mat> &images) {
65 
66  int n_images = images.size();
67 
68  int size;
69  int i;
70  int m, n;
71  int x, y;
72 
73  // w - Maximum number of images in a row
74  // h - Maximum number of images in a column
75  int w, h;
76 
77  // scale - How much we have to resize the image
78  float scale;
79  int max;
80 
81  // If the number of arguments is lesser than 0 or greater than 12
82  // return without displaying
83  if (n_images <= 0) {
84  printf("Number of arguments too small....\n");
85  return;
86  } else if (n_images > 14) {
87  printf("Number of arguments too large, can only handle maximally 12 images at a time ...\n");
88  return;
89  }
90 
91  // Determine the size of the image,
92  // and the number of rows/cols
93  // from number of arguments
94  else if (n_images == 1) {
95  w = h = 1;
96  size = 500;
97  } else if (n_images == 2) {
98  w = 1;
99  h = 2;
100  size = 500;
101  } else if (n_images == 3 || n_images == 4) {
102  w = 2;
103  h = 2;
104  size = 500;
105  } else if (n_images == 5 || n_images == 6) {
106  w = 3;
107  h = 2;
108  size = 200;
109  } else if (n_images == 7 || n_images == 8) {
110  w = 4;
111  h = 2;
112  size = 200;
113  } else {
114  w = 4;
115  h = 3;
116  size = 150;
117  }
118 
119  // Create a new 3 channel image
120  Mat DispImage = Mat::zeros(Size(100 + size * w, 60 + size * h), PixelFormat);
121 
122  // Loop for n_images number of arguments
123  for (i = 0, m = 20, n = 20; i < n_images; i++, m += (20 + size)) {
124 
125  // Check whether it is NULL or not
126  // If it is NULL, release the image, and return
127  if (images[i].empty()) {
128  printf("Invalid arguments");
129  return;
130  }
131 
132  // Find the width and height of the image
133  x = images[i].cols;
134  y = images[i].rows;
135 
136  // Find whether height or width is greater in order to resize the image
137  max = (x > y) ? x : y;
138 
139  // Find the scaling factor to resize the image
140  scale = (float)((float)max / float(size));
141 
142  // Used to Align the images
143  if (i % w == 0 && m != 20) {
144  m = 20;
145  n += 20 + size;
146  }
147 
148  // Set the image ROI to display the current image
149  // Resize the input image and copy the it to the Single Big Image
150  Rect ROI(m, n, (int)(float(x) / scale), (int)(float(y) / scale));
151  Mat temp;
152  resize(images[i], temp, Size(ROI.width, ROI.height));
153  temp.copyTo(DispImage(ROI));
154  }
155 
156  // Create a new window, and show the Single Big Image
157  imshow(title, DispImage);
158 }
showManyImages
void showManyImages(const string &title, const std::vector< cv::Mat > &images)
Definition: opencv_helpers.hpp:64