JeVois  1.2
JeVois Smart Embedded Machine Vision Toolkit
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  \ingroup utils */
55 
56  //! Aspect ratio of the JeVois camera
57  /*! \ingroup coordhelpers */
58 #define JEVOIS_CAMERA_ASPECT (4.0 / 3.0)
59 
60  //! Transform coordinates in-place from camera to standardized, using a RawImage to establish image size
61  /*! The RawImage from the camera is used to specify pixel width and height of the camera image, and this is the
62  source coordinate system. The destination coordinate system is the standardized one, with x in [-1000 ... 1000]
63  and y in [-750 ... 750].
64 
65  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
66  values over serial port.
67 
68  \ingroup coordhelpers */
69  void imgToStd(float & x, float & y, RawImage const & camimg, float const eps = 0.1F);
70 
71  //! Transform coordinates in-place from camera to standardized, using given image width and height
72  /*! The width and height are used to specify pixel width and height of the camera image, and this is the source
73  coordinate system. The destination coordinate system is the standardized one, with x in [-1000 ... 1000] and y
74  in [-750 ... 750].
75 
76  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
77  values over serial port.
78 
79  \ingroup coordhelpers */
80  void imgToStd(float & x, float & y, unsigned int const width, unsigned int const height, float const eps = 0.1F);
81 
82  //! Transform coordinates in-place from standardized to image, using a RawImage to establish image size
83  /*! The RawImage would typically be from the camera is used to specify pixel width and height of the camera image,
84  and this is the destination coordinate system. The source coordinate system is the standardized one, with x in
85  [-1000 ... 1000] and y in [-750 ... 750].
86 
87  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
88  values over serial port.
89 
90  \ingroup coordhelpers */
91  void stdToImg(float & x, float & y, RawImage const & camimg, float const eps = 0.1F);
92 
93  //! Transform coordinates in-place from standardized to image, using a RawImage to establish image size
94  /*! The witdth and height would typically be from the camera and are used to specify pixel width and height of the
95  camera image, and this is the destination coordinate system. The source coordinate system is the standardized
96  one, with x in [-1000 ... 1000] and y in [-750 ... 750].
97 
98  eps is used for rounding of returned coordinates, which is convenient to avoid sending very long floating point
99  values over serial port.
100 
101  \ingroup coordhelpers */
102  void stdToImg(float & x, float & y, unsigned int const width, unsigned int const height, float const eps = 0.1F);
103  }
104 }
105 
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 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:36