PICCANTE  0.4
The hottest HDR imaging library!
find_checker_board.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_JNI_FIND_CHECKER_BOARD_HPP
19 #define PIC_JNI_FIND_CHECKER_BOARD_HPP
20 
21 #include "../filtering/filter_luminance.hpp"
22 #include "../filtering/filter_downsampler_2d.hpp"
23 #include "../filtering/filter_white_balance.hpp"
24 
25 #include "../computer_vision/iterative_closest_point_2D.hpp"
26 #include "../computer_vision/nelder_mead_opt_ICP_2D.hpp"
27 
28 #include "../features_matching/orb_descriptor.hpp"
29 
30 #include "../computer_vision/find_checker_board.hpp"
31 
32 #include "../algorithms/binarization.hpp"
33 #include "../util/mask.hpp"
34 #include "../features_matching/canny_edge_detector.hpp"
35 
36 namespace pic {
37 
38 #ifndef PIC_DISABLE_EIGEN
39 
46 PIC_INLINE std::vector<int> extractCheckerBoardJNI(std::string imageInPath, std::string imageOutPath)
47 {
48  Image in;
49  bool bRead = in.Read(imageInPath, LT_NOR_GAMMA);
50 
51  std::vector<int> ret;
52  ret.clear();
53 
54  Image *work;
55 
56  if(bRead) {
57 
58  bool bScale = false;
59  float scale = 1.0f;
60 
61  if(in.nPixels() > 1000000) {
62 
63  int maxLength = MAX(in.width, in.height);
64 
65  scale = 1000.0f / float(maxLength);
66 
67 #ifdef PIC_DEBUG
68  printf("Down scale factor: %f\n", scale);
69 #endif
70 
71  work = FilterDownSampler2D::execute(&in, NULL, scale);
72 
73  bScale = true;
74  } else {
75  work = &in;
76  }
77 
78  std::vector< Eigen::Vector2f > corners;
79  pic::findCheckerBoard(work, corners);
80 
81  //
82  //scale
83  //
84  Eigen::Vector2f p0, p1;
85  float pixel_length = pic::estimateLengthOfCheckers(corners, p0, p1);
86 
87 #ifdef PIC_DEBUG
88  printf("Pixel length: %f\n", pixel_length);
89 #endif
90 
91  ret.push_back(int(p0[0] / scale));
92  ret.push_back(int(p0[1] / scale));
93  ret.push_back(int(p1[0] / scale));
94  ret.push_back(int(p1[1] / scale));
95 
96  //
97  //white balance
98  //
99  Eigen::Vector2f pw = pic::estimateCoordinatesWhitePointFromCheckerBoard(work, corners, 4, 6);
100 
101  ret.push_back(int(pw[0] / scale));
102  ret.push_back(int(pw[1] / scale));
103 
104  Image* img_wb;
105  if(bScale) {
106  int patchSize = 5;
107  BBox patch(int(pw[0]) - patchSize,
108  int(pw[0]) + patchSize,
109  int(pw[1]) - patchSize,
110  int(pw[1]) + patchSize);
111  float *white_color = work->getMeanVal(&patch, NULL);
112  img_wb = FilterWhiteBalance::execute(&in, white_color, NULL);
113  } else {
114  img_wb = FilterWhiteBalance::execute(&in, int(pw[0]), int(pw[1]), true, NULL);
115  }
116 
117  if(img_wb != NULL) {
118  bool bWrite = img_wb->Write(imageOutPath.c_str(), LT_NOR_GAMMA, 0);
119 
120  if(!bWrite) {
121  printf("extractCheckerBoardJNI: the image could not be written.\n");
122  }
123 
124  delete img_wb;
125  }
126  }
127 
128  return ret;
129 }
130 
131 #endif
132 
133 } // end namespace pic
134 
135 #endif // PIC_JNI_FIND_CHECKER_BOARD_HPP
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
float * getMeanVal(BBox *box, float *ret)
getMeanVal computes the mean for the current Image.
PIC_INLINE Eigen::Vector2f estimateCoordinatesWhitePointFromCheckerBoard(Image *img, std::vector< Eigen::Vector2f > &corners_model, int checkerBoardSizeX=4, int checkerBoardSizeY=6)
estimateCoordinatesWhitePointFromCheckerBoard
Definition: find_checker_board.hpp:483
static Image * execute(Image *imgIn, Image *imgOut, int width, int height)
execute
Definition: filter_downsampler_2d.hpp:100
int nPixels() const
nPixels computes the number of pixels.
Definition: image.hpp:499
PIC_INLINE std::vector< int > extractCheckerBoardJNI(std::string imageInPath, std::string imageOutPath)
extractCheckerBoardJNI
Definition: find_checker_board.hpp:46
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static Image * execute(Image *imgIn, float *white_color, Image *out)
execute
Definition: filter_white_balance.hpp:162
Definition: dynamic_range.hpp:29
Definition: bilateral_separation.hpp:25
#define MAX(a, b)
Definition: math.hpp:73
bool Read(std::string nameFile, LDR_type typeLoad)
Read opens an Image from a file on the disk.
PIC_INLINE float estimateLengthOfCheckers(std::vector< Eigen::Vector2f > &corners_model, Eigen::Vector2f &p0, Eigen::Vector2f &p1)
estimateLengthInPixelOfCheckers
Definition: find_checker_board.hpp:446
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
PIC_INLINE void findCheckerBoard(Image *img, std::vector< Eigen::Vector2f > &corners_model, int checkerBoardSizeX=4, int checkerBoardSizeY=7)
findCheckerBoard
Definition: find_checker_board.hpp:259