MRPT  2.0.4
checkerboard_ocamcalib_detector.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 // Universal include for all versions of OpenCV
13 #include <mrpt/3rdparty/do_opencv_includes.h>
14 #include <mrpt/img/CImage.h>
15 
16 #include <cmath>
17 #include <cstdio>
18 
19 #include <memory>
20 
21 #if MRPT_HAS_OPENCV
22 
23 // Debug visualizations...
24 // Ming #define VIS 1
25 #define VIS 0
26 
27 // Definition Contour Struct
29 {
30  CV_CONTOUR_FIELDS()
31  int counter;
32 };
33 
34 // Definition Corner Struct
35 struct CvCBCorner;
36 
37 struct CvCBCorner
38 {
40  CvCBCorner() = default;
41  CvPoint2D32f pt; // X and y coordinates
42  int row{-1000}; // Row and column of the corner
43  int column{-1000}; // in the found pattern
44  bool needsNeighbor; // Does the corner require a neighbor?
45  int count{0}; // number of corner neighbors
46  CvCBCorner::Ptr neighbors[4]; // pointer to all corner neighbors
47 };
48 
49 // Definition Quadrangle Struct
50 // This structure stores information about the chessboard quadrange
51 struct CvCBQuad;
52 
53 struct CvCBQuad
54 {
56  CvCBQuad() = default;
57 
58  int count{0}; // Number of quad neihbors
59  int group_idx{0}; // Quad group ID
60  float edge_len{0}; // Smallest side length^2
61  CvCBCorner::Ptr corners[4]; // CvCBCorner *corners[4]; //
62  // Coordinates of quad corners
63  CvCBQuad::Ptr neighbors[4]; // Pointers of quad neighbors
64  bool labeled{false}; // Has this corner been labeled?
65  double area{0.0}, area_ratio{1.0};
66 };
67 
68 //===========================================================================
69 // PUBLIC FUNCTION PROTOTYPES
70 //===========================================================================
71 // Return: -1: errors, 0: not found, 1: found OK
73  const mrpt::img::CImage& img_, CvSize pattern_size,
74  std::vector<CvPoint2D32f>& out_corners);
75 
76 // Return: true: found OK
78  const mrpt::img::CImage& img_, CvSize pattern_size,
79  std::vector<std::vector<CvPoint2D32f>>& out_corners);
80 
81 //===========================================================================
82 // INTERNAL FUNCTION PROTOTYPES
83 //===========================================================================
85  std::vector<CvCBQuad::Ptr>& quads, std::vector<CvCBCorner::Ptr>& corners,
86  const mrpt::img::CImage& img, int flags, int dilation, bool firstRun);
87 
88 void mrFindQuadNeighbors2(std::vector<CvCBQuad::Ptr>& quads, int dilation);
89 
91  std::vector<CvCBQuad::Ptr>& new_quads, int new_dilation,
92  std::vector<CvCBQuad::Ptr>& old_quads, int old_dilation);
93 
95  std::vector<CvCBQuad::Ptr>& in_quads,
96  std::vector<CvCBQuad::Ptr>& out_quad_group, const int group_idx,
97  const int dilation);
98 
99 void mrLabelQuadGroup(
100  std::vector<CvCBQuad::Ptr>& quad_group, const CvSize& pattern_size,
101  bool firstRun);
102 
103 // Remove quads' extra quads until reached the expected number of quads.
105  std::vector<CvCBQuad::Ptr>& quads, const CvSize& pattern_size);
106 
107 // JL: Return 1 on success in finding all the quads, 0 on didn't, -1 on error.
108 int myQuads2Points(
109  const std::vector<CvCBQuad::Ptr>& output_quads, const CvSize& pattern_size,
110  std::vector<CvPoint2D32f>& out_corners);
111 
112 // JL: Make unique all the (smart pointers-pointed) objects in the list and
113 // neighbors lists.
114 void quadListMakeUnique(std::vector<CvCBQuad::Ptr>& quads);
115 
116 // JL: Refactored code from within cvFindChessboardCorners3() and alternative
117 // algorithm:
119  mrpt::img::CImage& thresh_img, const int dilations,
120  IplConvKernel* kernel_cross, IplConvKernel* kernel_rect,
121  IplConvKernel* kernel_diag1, IplConvKernel* kernel_diag2,
122  IplConvKernel* kernel_horz, IplConvKernel* kernel_vert);
123 
124 #endif // MRPT_HAS_OPENCV
void mrLabelQuadGroup(std::vector< CvCBQuad::Ptr > &quad_group, const CvSize &pattern_size, bool firstRun)
void quadListMakeUnique(std::vector< CvCBQuad::Ptr > &quads)
int myQuads2Points(const std::vector< CvCBQuad::Ptr > &output_quads, const CvSize &pattern_size, std::vector< CvPoint2D32f > &out_corners)
int cvFindChessboardCorners3(const mrpt::img::CImage &img_, CvSize pattern_size, std::vector< CvPoint2D32f > &out_corners)
bool do_special_dilation(mrpt::img::CImage &thresh_img, const int dilations, IplConvKernel *kernel_cross, IplConvKernel *kernel_rect, IplConvKernel *kernel_diag1, IplConvKernel *kernel_diag2, IplConvKernel *kernel_horz, IplConvKernel *kernel_vert)
int icvGenerateQuads(std::vector< CvCBQuad::Ptr > &quads, std::vector< CvCBCorner::Ptr > &corners, const mrpt::img::CImage &img, int flags, int dilation, bool firstRun)
void icvCleanFoundConnectedQuads(std::vector< CvCBQuad::Ptr > &quads, const CvSize &pattern_size)
int mrAugmentBestRun(std::vector< CvCBQuad::Ptr > &new_quads, int new_dilation, std::vector< CvCBQuad::Ptr > &old_quads, int old_dilation)
bool find_chessboard_corners_multiple(const mrpt::img::CImage &img_, CvSize pattern_size, std::vector< std::vector< CvPoint2D32f >> &out_corners)
void icvFindConnectedQuads(std::vector< CvCBQuad::Ptr > &in_quads, std::vector< CvCBQuad::Ptr > &out_quad_group, const int group_idx, const int dilation)
void mrFindQuadNeighbors2(std::vector< CvCBQuad::Ptr > &quads, int dilation)
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020