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