appkit  1.5.1
RoadNarrows Robotics Application Kit
WinCvIoI.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_win
8 //
9 // File: WinCvIoI.h
10 //
11 /*! \file
12  *
13  * $LastChangedDate: 2013-05-03 07:45:13 -0600 (Fri, 03 May 2013) $
14  * $Rev: 2904 $
15  *
16  * \brief RoadNarrows Robotics OpenCV Image of Interest class interface.
17  *
18  * \author Robin Knight (robin.knight@roadnarrows.com)
19  * \author Daniel Packard (daniel@roadnarrows.com)
20  *
21  * \par Copyright
22  * \h_copy 2011-2017. RoadNarrows LLC.\n
23  * http://www.roadnarrows.com\n
24  * All Rights Reserved
25  */
26 /*
27  * @EulaBegin@
28  *
29  * Permission is hereby granted, without written agreement and without
30  * license or royalty fees, to use, copy, modify, and distribute this
31  * software and its documentation for any purpose, provided that
32  * (1) The above copyright notice and the following two paragraphs
33  * appear in all copies of the source code and (2) redistributions
34  * including binaries reproduces these notices in the supporting
35  * documentation. Substantial modifications to this software may be
36  * copyrighted by their authors and need not follow the licensing terms
37  * described here, provided that the new terms are clearly indicated in
38  * all files where they apply.
39  *
40  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
41  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
42  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
43  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
44  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
45  * THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
49  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
50  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
52  *
53  * @EulaEnd@
54  */
55 ////////////////////////////////////////////////////////////////////////////////
56 
57 #ifndef _RNR_WIN_CV_IOI_H
58 #define _RNR_WIN_CV_IOI_H
59 
60 #include "rnr/rnrconfig.h"
61 
62 #include "opencv2/core/core.hpp"
63 
64 #include "rnr/appkit/Win.h"
65 
66 /*!
67  * \brief RoadNarrows Robotics
68  */
69 namespace rnr
70 {
71  //...........................................................................
72  // Class WinCvIoI
73  //...........................................................................
74 
75  /*!
76  * Window OpenCV Image of Interest (IoI) Class.
77  *
78  * An IoI is typically at a higher resolution the what can be showed on a
79  * display. Moreover, the display of IoI may require rotation and alignment.
80  */
81  class WinCvIoI
82  {
83  public:
84  /*!
85  * \brief Image of Interest class initialization constructor.
86  *
87  * Initialize the transformations needed to place a IoI in the window.
88  *
89  * \param sizeIoI Size of hi-res Image of Interest.
90  * \param sizeTgt Size of target workspace, oriented at 0 degrees.
91  * \param eOpRot Target image rotation operation.
92  * See \ref rnmpwin_rot.
93  * \param eOpAlign Target image alignment operation.
94  * See \ref rnmpwin_align.
95  * \param bCropToFit If true, the transformed image is cropped to fit
96  * into target size. Otherwise the transformed image is
97  * scaled to fit.
98  */
99  WinCvIoI(cv::Size &sizeIoI,
100  cv::Size &sizeTgt,
101  RotOp eOpRot,
102  AlignOp eOpAlign,
103  bool bCropToFit);
104 
105  /*!
106  * \brief Destructor.
107  */
108  virtual ~WinCvIoI() { }
109 
110  /*!
111  * \brief Set Image of Interest transfromation parameters.
112  *
113  * Initialize the transformations needed to place a IoI in the window.
114  *
115  * \param sizeIoI Size of hi-res Image of Interest.
116  * \param rectRoIIoI Region of Interest within Image of Interest.
117  * \param sizeTgt Size of target workspace, oriented at 0 degrees.
118  * \param eOpRot Target image rotation operation.
119  * See \ref rnmpwin_rot.
120  * \param eOpAlign Target image alignment operation.
121  * See \ref rnmpwin_align.
122  * \param bCropToFit If true, the transformed image is cropped to fit
123  * into target size. Otherwise the transformed image is
124  * scaled to fit.
125 
126  */
127  void setTransformParams(cv::Size &sizeIoI,
128  cv::Rect &rectRoIIoI,
129  cv::Size &sizeTgt,
130  RotOp eOpRot,
131  AlignOp eOpAlign,
132  bool bCropToFit);
133 
134  /*!
135  * \brief Transform Image of Interest into the target image.
136  *
137  * \param imgIoI Image of Interest.
138  * \param [in, out]imgTgt Target image. Must be of size of RDK?
139  */
140  virtual void transform(cv::Mat &imgIoI, cv::Mat &imgTgt);
141 
142  /*!
143  * \brief Map display pixel coordinates to Image of Interest pixel
144  * coordinates.
145  *
146  * \param ptDisplay Point in display coordinates.
147  *
148  * \return Cooresponding point in target IoI.
149  */
150  cv::Point mapPoint(cv::Point &ptDisplay);
151 
152  /*!
153  * \breif Get the IoI original size.
154  *
155  * \return Size.
156  */
157  cv::Size getOriginalSize()
158  {
159  return cv::Size(m_sizeIoI.width, m_sizeIoI.height);
160  }
161 
162  /*!
163  * \brief Get the transformed target size.
164  *
165  * \return Size.
166  */
168  {
169  return cv::Size(m_rectRoITgt.width, m_rectRoITgt.height);
170  }
171 
172  /*!
173  * \brief Calculate the maximal size the source can fit into the target
174  * size while keeping a 4:3 aspect ratio.
175  *
176  * \param sizeSrc Source size.
177  * \param sizeTgt Target size.
178  *
179  * \return Maximum size.
180  */
181  cv::Size calcMaxFit43(cv::Size &sizeSrc, cv::Size &sizeTgt);
182 
183  protected:
184  cv::Size m_sizeIoI; ///< image native size
185  cv::Rect m_rectRoIIoI; ///< image of interest region of interest
186  cv::Size m_sizeTgt; ///< target workspace size
187  cv::Rect m_rectRoITgt; ///< target workspace region of interest
188  RotOp m_eOpRot; ///< image rotation operator
189  cv::Mat m_matRot; ///< 2x3 transformation matrix
190  cv::Size m_sizeRotated; ///< rotated image size
191  bool m_bOpRotate; ///< do [not] apply rotation operation
192  bool m_bOpScale; ///< do [not] apply resize operation
193  cv::Size m_sizeScaled; ///< scaled image size
194  bool m_bOpCrop; ///< do [not] apply crop operation
195  cv::Rect m_rectRoICropped; ///< cropped region of interest
196  AlignOp m_eOpAlign; ///< image alignment operator
197  };
198 
199 } // namespace
200 
201 
202 #endif // _RNR_WIN_CV_IOI_H
cv::Rect m_rectRoIIoI
image of interest region of interest
Definition: WinCvIoI.h:185
RotOp
Definition: Win.h:97
cv::Size calcMaxFit43(cv::Size &sizeSrc, cv::Size &sizeTgt)
Calculate the maximal size the source can fit into the target size while keeping a 4:3 aspect ratio...
Definition: WinCvIoI.cxx:365
bool m_bOpRotate
do [not] apply rotation operation
Definition: WinCvIoI.h:191
virtual void transform(cv::Mat &imgIoI, cv::Mat &imgTgt)
Transform Image of Interest into the target image.
Definition: WinCvIoI.cxx:266
RoadNarrows Robotics Win abstract base class interface.
cv::Size m_sizeTgt
target workspace size
Definition: WinCvIoI.h:186
cv::Size getOriginalSize()
Definition: WinCvIoI.h:157
cv::Point mapPoint(cv::Point &ptDisplay)
Map display pixel coordinates to Image of Interest pixel coordinates.
Definition: WinCvIoI.cxx:302
bool m_bOpScale
do [not] apply resize operation
Definition: WinCvIoI.h:192
AlignOp
Definition: Win.h:81
cv::Size m_sizeRotated
rotated image size
Definition: WinCvIoI.h:190
cv::Rect m_rectRoITgt
target workspace region of interest
Definition: WinCvIoI.h:187
cv::Size m_sizeIoI
image native size
Definition: WinCvIoI.h:184
bool m_bOpCrop
do [not] apply crop operation
Definition: WinCvIoI.h:194
cv::Mat m_matRot
2x3 transformation matrix
Definition: WinCvIoI.h:189
RotOp m_eOpRot
image rotation operator
Definition: WinCvIoI.h:188
cv::Rect m_rectRoICropped
cropped region of interest
Definition: WinCvIoI.h:195
virtual ~WinCvIoI()
Destructor.
Definition: WinCvIoI.h:108
WinCvIoI(cv::Size &sizeIoI, cv::Size &sizeTgt, RotOp eOpRot, AlignOp eOpAlign, bool bCropToFit)
Image of Interest class initialization constructor.
Definition: WinCvIoI.cxx:82
cv::Size getTransformedSize()
Get the transformed target size.
Definition: WinCvIoI.h:167
AlignOp m_eOpAlign
image alignment operator
Definition: WinCvIoI.h:196
cv::Size m_sizeScaled
scaled image size
Definition: WinCvIoI.h:193
RoadNarrows Robotics.
Definition: Camera.h:74
void setTransformParams(cv::Size &sizeIoI, cv::Rect &rectRoIIoI, cv::Size &sizeTgt, RotOp eOpRot, AlignOp eOpAlign, bool bCropToFit)
Set Image of Interest transfromation parameters.
Definition: WinCvIoI.cxx:94