JeVois  1.5
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Coordinates.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #include <jevois/Image/RawImage.H>
21 
22 namespace jevois
23 {
24  namespace coords
25  {
26  /*! \defgroup coordhelpers Helper functions to convert coordinates from camera resolution to standardized
27 
28  Different machine vision algorithms in JeVois may be able to operate with different camera resolutions, such as
29  1280x1024, 320x240, or 176x144. When some item of interest is detected in the camera frame, one may often want
30  to send the coordinates of that thing to the serial port. This poses a problem if one were to directly send the
31  image coordinates of the item out, which is that now the receiver (e.g., an Arduino) needs to know which camera
32  image resolution was used, so that it can properly interpret these coordinates. For example, if the visual
33  attention (saliency) algorithm is running with 640x480 camera input, then a salient object at the center of the
34  camera's field of view would have coordinates 320,240. But if the same saliency algorithm is configures to
35  process 320x240 input ideo (so that it can run at a higher framerate), now an object at the center of the field
36  of view would have coordinates 160,120. If one connects an Arduino that controls, for example, a pan/tilt head
37  to JeVois, we need a way to communicate coordinates of target objects in the world independently of the video
38  resolution used by the camera.
39 
40  Thus, JeVois defines a standardized coordinate system, as follows:
41 
42  - center fo the camera's field of view is at x=0, y=0
43  - left edge of the camera image is always at x=-1000
44  - right edge of the camera image is always at x=1000
45  - top edge of the camera image is always at y=-750
46  - bottom edge of the camera image is always at y=750
47 
48  Note that the value of 750 here comes from the assumption of a 4:3 aspect ratio for the camera sensor, and is
49  actually defined in JEVOIS_CAMERA_ASPECT.
50 
51  When writing a machine vision algorithm that sends over serial the coordinates of things detected in the camera
52  frames, be sure to first transform those coordinates from image to standardized space.
53 
54  For more on how standardized coordinates are used to communicate with embedded controllers, and for 3D
55  coordinates, see \ref UserSerialStyle
56 
57  \ingroup utils */
58 
59  //! Aspect ratio of the JeVois camera
60  /*! \ingroup coordhelpers */
61 #define JEVOIS_CAMERA_ASPECT (4.0 / 3.0)
62 
63  //! Transform coordinates in-place from camera to standardized, using a RawImage to establish image size
64  /*! The RawImage from the camera is used to specify pixel width and height of the camera image, and this is the
65  source coordinate system. The destination coordinate system is the standardized one, with x in [-1000 ... 1000]
66  and y in [-750 ... 750].
67 
68  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
69  values over serial port.
70 
71  \ingroup coordhelpers */
72  void imgToStd(float & x, float & y, RawImage const & camimg, float const eps = 0.1F);
73 
74  //! Transform coordinates in-place from camera to standardized, using given image width and height
75  /*! The width and height are used to specify pixel width and height of the camera image, and this is the source
76  coordinate system. The destination coordinate system is the standardized one, with x in [-1000 ... 1000] and y
77  in [-750 ... 750].
78 
79  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
80  values over serial port.
81 
82  \ingroup coordhelpers */
83  void imgToStd(float & x, float & y, unsigned int const width, unsigned int const height, float const eps = 0.1F);
84 
85  //! Transform X coordinate in-place from camera to standardized, using given image width and height
86  /*! The width is used to specify pixel width of the camera image, and this is the source
87  coordinate system. The destination coordinate system is the standardized one, with x in [-1000 ... 1000].
88 
89  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
90  values over serial port.
91 
92  \ingroup coordhelpers */
93  void imgToStdX(float & x, unsigned int const width, float const eps = 0.1F);
94 
95  //! Transform Y coordinate in-place from camera to standardized, using given image width and height
96  /*! The height is used to specify pixel height of the camera image, and this is the source
97  coordinate system. The destination coordinate system is the standardized one, with y in [-750 ... 750].
98 
99  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
100  values over serial port.
101 
102  \ingroup coordhelpers */
103  void imgToStdY(float & y, unsigned int const height, float const eps = 0.1F);
104 
105  //! Transform size in-place from camera to standardized, using given image width and height
106  /*! Arguments w and h define the size of an object in pixels, which will be converted to standardized units. The
107  width and height are used to specify pixel width and height of the camera image, and this is the source
108  coordinate system. The destination coordinate system is the standardized one, with x in [-1000 ... 1000] and y
109  in [-750 ... 750].
110 
111  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
112  values over serial port.
113 
114  \ingroup coordhelpers */
115  void imgToStdSize(float & w, float & h, unsigned int const width, unsigned int const height,
116  float const eps = 0.1F);
117 
118  //! Transform coordinates in-place from standardized to image, using a RawImage to establish image size
119  /*! The RawImage would typically be from the camera is used to specify pixel width and height of the camera image,
120  and this is the destination coordinate system. The source coordinate system is the standardized one, with x in
121  [-1000 ... 1000] and y in [-750 ... 750].
122 
123  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
124  values over serial port.
125 
126  \ingroup coordhelpers */
127  void stdToImg(float & x, float & y, RawImage const & camimg, float const eps = 0.1F);
128 
129  //! Transform coordinates in-place from standardized to image, using a RawImage to establish image size
130  /*! The width and height would typically be from the camera and are used to specify pixel width and height of the
131  camera image, and this is the destination coordinate system. The source coordinate system is the standardized
132  one, with x in [-1000 ... 1000] and y in [-750 ... 750].
133 
134  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
135  values over serial port.
136 
137  \ingroup coordhelpers */
138  void stdToImg(float & x, float & y, unsigned int const width, unsigned int const height, float const eps = 0.1F);
139 
140  //! Transform size in-place from standardized to image, using a RawImage to establish image size
141  /*! Arguments w and h define the size of an object in standardized units, which will be converted to pixels. The
142  width and height would typically be from the camera and are used to specify pixel width and height of the
143  camera image, and this is the destination coordinate system. The source coordinate system is the standardized
144  one, with x in [-1000 ... 1000] and y in [-750 ... 750].
145 
146  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
147  values over serial port.
148 
149  \ingroup coordhelpers */
150  void stdToImgSize(float & x, float & y, unsigned int const width, unsigned int const height,
151  float const eps = 0.1F);
152  }
153 }
154 
void imgToStdY(float &y, unsigned int const height, float const eps=0.1F)
Transform Y coordinate in-place from camera to standardized, using given image width and height...
Definition: Coordinates.C:43
void imgToStd(float &x, float &y, RawImage const &camimg, float const eps=0.1F)
Transform coordinates in-place from camera to standardized, using a RawImage to establish image size...
Definition: Coordinates.C:22
void stdToImgSize(float &x, float &y, unsigned int const width, unsigned int const height, float const eps=0.1F)
Transform size in-place from standardized to image, using a RawImage to establish image size...
Definition: Coordinates.C:74
void stdToImg(float &x, float &y, RawImage const &camimg, float const eps=0.1F)
Transform coordinates in-place from standardized to image, using a RawImage to establish image size...
Definition: Coordinates.C:60
void imgToStdSize(float &w, float &h, unsigned int const width, unsigned int const height, float const eps=0.1F)
Transform size in-place from camera to standardized, using given image width and height.
Definition: Coordinates.C:50
void imgToStdX(float &x, unsigned int const width, float const eps=0.1F)
Transform X coordinate in-place from camera to standardized, using given image width and height...
Definition: Coordinates.C:36