Main MRPT website > C++ reference for MRPT 1.5.7
vision/src/sift-hess/utils.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #ifndef UTILS_H
11 #define UTILS_H
12 
13 //#include "cxcore.h"
14 // Universal include for all versions of OpenCV
15 #include <mrpt/otherlibs/do_opencv_includes.h>
16 
17 #include <stdio.h>
18 
19 #ifdef __cplusplus
20  extern "C" {
21 #endif
22 
23 
24 /* absolute value */
25 #ifndef ABS
26 #define ABS(x) ( ( x < 0 )? -x : x )
27 #endif
28 
29 
30 /***************************** Inline Functions ******************************/
31 
32 
33 /**
34 A function to get a pixel value from an 8-bit unsigned image.
35 
36 @param img an image
37 @param r row
38 @param c column
39 @return Returns the value of the pixel at (\a r, \a c) in \a img
40 */
41 static __inline int pixval8( IplImage* img, int r, int c )
42 {
43  return (int)( ( (uchar*)(img->imageData + img->widthStep*r) )[c] );
44 }
45 
46 
47 /**
48 A function to set a pixel value in an 8-bit unsigned image.
49 
50 @param img an image
51 @param r row
52 @param c column
53 @param val pixel value
54 */
55 static __inline void setpix8( IplImage* img, int r, int c, uchar val)
56 {
57  ( (uchar*)(img->imageData + img->widthStep*r) )[c] = val;
58 }
59 
60 
61 /**
62 A function to get a pixel value from a 32-bit floating-point image.
63 
64 @param img an image
65 @param r row
66 @param c column
67 @return Returns the value of the pixel at (\a r, \a c) in \a img
68 */
69 static __inline float pixval32f( IplImage* img, int r, int c )
70 {
71  return ( (float*)(img->imageData + img->widthStep*r) )[c];
72 }
73 
74 
75 /**
76 A function to set a pixel value in a 32-bit floating-point image.
77 
78 @param img an image
79 @param r row
80 @param c column
81 @param val pixel value
82 */
83 static __inline void setpix32f( IplImage* img, int r, int c, float val )
84 {
85  ( (float*)(img->imageData + img->widthStep*r) )[c] = val;
86 }
87 
88 
89 /**
90 A function to get a pixel value from a 64-bit floating-point image.
91 
92 @param img an image
93 @param r row
94 @param c column
95 @return Returns the value of the pixel at (\a r, \a c) in \a img
96 */
97 static __inline double pixval64f( IplImage* img, int r, int c )
98 {
99  return (double)( ( (double*)(img->imageData + img->widthStep*r) )[c] );
100 }
101 
102 
103 /**
104 A function to set a pixel value in a 64-bit floating-point image.
105 
106 @param img an image
107 @param r row
108 @param c column
109 @param val pixel value
110 */
111 static __inline void setpix64f( IplImage* img, int r, int c, double val )
112 {
113  ( (double*)(img->imageData + img->widthStep*r) )[c] = val;
114 }
115 
116 
117 /**************************** Function Prototypes ****************************/
118 
119 
120 /**
121 Prints an error message and aborts the program. The error message is
122 of the form "Error: ...", where the ... is specified by the \a format
123 argument
124 
125 @param format an error message format string (as with \c printf(3)).
126 */
127 extern void fatal_error( char* format, ... );
128 
129 
130 /**
131 Replaces a file's extension, which is assumed to be everything after the
132 last dot ('.') character.
133 
134 @param file the name of a file
135 
136 @param extn a new extension for \a file; should not include a dot (i.e.
137  \c "jpg", not \c ".jpg") unless the new file extension should contain
138  two dots.
139 
140 @return Returns a new string formed as described above. If \a file does
141  not have an extension, this function simply adds one.
142 */
143 extern char* replace_extension( const char* file, const char* extn );
144 
145 
146 /**
147 A function that removes the path from a filename. Similar to the Unix
148 basename command.
149 
150 @param pathname a (full) path name
151 
152 @return Returns the basename of \a pathname.
153 */
154 // JLBC: Changed for MRPT: It's already declared in string.h
155 //extern char* basename( const char* pathname );
156 
157 /**
158 Displays progress in the console with a spinning pinwheel. Every time this
159 function is called, the state of the pinwheel is incremented. The pinwheel
160 has four states that loop indefinitely: '|', '/', '-', '\'.
161 
162 @param done if 0, this function simply increments the state of the pinwheel;
163  otherwise it prints "done"
164 */
165 extern void progress( int done );
166 
167 
168 /**
169 Erases a specified number of characters from a stream.
170 
171 @param stream the stream from which to erase characters
172 @param n the number of characters to erase
173 */
174 extern void erase_from_stream( FILE* stream, int n );
175 
176 
177 /**
178 Doubles the size of an array with error checking
179 
180 @param array pointer to an array whose size is to be doubled
181 @param n number of elements allocated for \a array
182 @param size size in bytes of elements in \a array
183 
184 @return Returns the new number of elements allocated for \a array. If no
185  memory is available, returns 0 and frees array.
186 */
187 extern int array_double( void** array, int n, int size );
188 
189 
190 /**
191 Calculates the squared distance between two points.
192 
193 @param p1 a point
194 @param p2 another point
195 */
196 extern double dist_sq_2D( CvPoint2D64f p1, CvPoint2D64f p2 );
197 
198 
199 /**
200 Draws an x on an image.
201 
202 @param img an image
203 @param pt the center point of the x
204 @param r the x's radius
205 @param w the x's line weight
206 @param color the color of the x
207 */
208 extern void draw_x( IplImage* img, CvPoint pt, int r, int w, CvScalar color );
209 
210 
211 /**
212 Combines two images by scacking one on top of the other
213 
214 @param img1 top image
215 @param img2 bottom image
216 
217 @return Returns the image resulting from stacking \a img1 on top if \a img2
218 */
219 extern IplImage* stack_imgs( IplImage* img1, IplImage* img2 );
220 
221 
222 /**
223 Allows user to view an array of images as a video. Keyboard controls
224 are as follows:
225 
226 <ul>
227 <li>Space - start and pause playback</li>
228 <li>Page Up - skip forward 10 frames</li>
229 <li>Page Down - jump back 10 frames</li>
230 <li>Right Arrow - skip forward 1 frame</li>
231 <li>Left Arrow - jump back 1 frame</li>
232 <li>Backspace - jump back to beginning</li>
233 <li>Esc - exit playback</li>
234 <li>Closing the window also exits playback</li>
235 </ul>
236 
237 @param imgs an array of images
238 @param n number of images in \a imgs
239 @param win_name name of window in which images are displayed
240 */
241 extern void vid_view( IplImage** imgs, int n, char* win_name );
242 
243 
244 /**
245 Checks if a HighGUI window is still open or not
246 
247 @param name the name of the window we're checking
248 
249 @return Returns 1 if the window named \a name has been closed or 0 otherwise
250 */
251 extern int win_closed( char* name );
252 
253 #ifdef __cplusplus
254  }
255 #endif
256 
257 #endif
IplImage * stack_imgs(IplImage *img1, IplImage *img2)
Combines two images by scacking one on top of the other
static __inline float pixval32f(IplImage *img, int r, int c)
A function to get a pixel value from a 32-bit floating-point image.
GLenum GLsizei n
Definition: glext.h:4618
static __inline int pixval8(IplImage *img, int r, int c)
A function to get a pixel value from an 8-bit unsigned image.
static __inline void setpix64f(IplImage *img, int r, int c, double val)
A function to set a pixel value in a 64-bit floating-point image.
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
GLuint color
Definition: glext.h:7093
void erase_from_stream(FILE *stream, int n)
Erases a specified number of characters from a stream.
void vid_view(IplImage **imgs, int n, char *win_name)
Allows user to view an array of images as a video.
const GLubyte * c
Definition: glext.h:5590
GLint GLvoid * img
Definition: glext.h:3645
double dist_sq_2D(CvPoint2D64f p1, CvPoint2D64f p2)
Calculates the squared distance between two points.
int win_closed(char *name)
Checks if a HighGUI window is still open or not
int val
Definition: mrpt_jpeglib.h:953
char * replace_extension(const char *file, const char *extn)
Replaces a file&#39;s extension, which is assumed to be everything after the last dot (&#39;...
static __inline void setpix32f(IplImage *img, int r, int c, float val)
A function to set a pixel value in a 32-bit floating-point image.
void progress(int done)
A function that removes the path from a filename.
GLdouble GLdouble GLdouble r
Definition: glext.h:3618
GLuint const GLchar * name
Definition: glext.h:3891
GLenum GLsizei GLenum format
Definition: glext.h:3513
GLsizeiptr size
Definition: glext.h:3779
int array_double(void **array, int n, int size)
Doubles the size of an array with error checking
void draw_x(IplImage *img, CvPoint pt, int r, int w, CvScalar color)
Draws an x on an image.
static __inline double pixval64f(IplImage *img, int r, int c)
A function to get a pixel value from a 64-bit floating-point image.
static __inline void setpix8(IplImage *img, int r, int c, uchar val)
A function to set a pixel value in an 8-bit unsigned image.
void fatal_error(char *format,...)
Prints an error message and aborts the program.



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019