easimage
easimage.h
Go to the documentation of this file.
1 
10 #ifndef _EASIMAGE_H_
11 #define _EASIMAGE_H_
12 
13 #include <linux/videodev2.h>
14 #include <SDL/SDL.h>
15 
16 #define QUOTE(name) #name
17 #define STR(macro) QUOTE(macro)
18 
24 #define RGB24 V4L2_PIX_FMT_RGB24
25 #define BGR24 V4L2_PIX_FMT_BGR24
26 #define YUYV V4L2_PIX_FMT_YUYV
27 #define RGB32 V4L2_PIX_FMT_RGB32
28 #define RGBA32 V4L2_PIX_FMT_RGB32
29 #define RGB48 V4L2_PIX_FMT_RGB48
30 #define GREY V4L2_PIX_FMT_GREY
31 #define MJPEG V4L2_PIX_FMT_MJPEG
32 
34 #define min(a,b) ( a<b ? a : b )
35 #define max(a,b) ( a>b ? a : b )
36 
37 
39 extern int easimageAppEnd;
40 
42 //forward declarations of internal types
43 struct Buffer;
44 
46 typedef struct {
47  unsigned int width;
48  unsigned int height;
49  unsigned int format;
50  char *name;
51  int handle;
52  struct Buffer *buffers;
53  unsigned int n_buffers;
54 } Camera;
55 
57 typedef struct {
58  unsigned int width;
59  unsigned int height;
60  unsigned short int depth;
61  unsigned int format;
62  unsigned char *mem_ptr;
63  unsigned char *data;
64  char *name;
65 } Image;
66 
68 typedef struct {
69  unsigned int width;
70  unsigned int height;
71  SDL_Surface *screen;
72 } Viewer;
73 
74 
81 void init_easimage();
83 void quit_easimage();
84 void waitTime(unsigned int milliseconds);
85 long int GetTime();
86 int kbhit();
87 int appProcEvents();
88 
96 Camera * camOpen(char *dev_name, unsigned int width, unsigned int height, int format);
97 unsigned int camGetWidth(Camera * cam);
98 unsigned int camGetHeight(Camera * cam);
99 Image * camGrabNewImage(Camera * cam);
100 int camGrabImage(Camera * cam, Image * img);
101 void camClose(Camera * cam);
102 int camPrintCaps(Camera *cam);
110 Image *imgNew(unsigned int width, unsigned int height, unsigned short depth);
111 Image *imgFromBitmap(const char *filename);
112 Image *imgFromPPM(const char *filename);
113 Image *imgFromFile(const char *filename);
114 int imgSavePPM(Image *img, char *fname);
115 int imgSavePAM(Image *img, char *fname);
116 int imgSaveRAW(Image *img, char *fname);
117 Image *imgCopy(Image * img);
118 void imgScale(Image *img, unsigned int sfactor);
119 Image *imgCrop(Image *img, int x1, int y1, int x2, int y2);
120 Image *imgCreateGaussian(int dim, float sig);
121 Image *imgConvolution(Image *img1, Image *img2, Image *res);
122 int imgFindPattern(Image *img, Image *pattern, int *x, int *y);
123 int imgFindPatternArea(Image *img, Image *pattern, int x1, int y1, int x2, int y2, int *x, int *y);
124 void imgDestroy(Image * img);
125 void imgMakeSymmetricX(Image *img);
126 void imgMakeSymmetricY(Image *img);
127 void imgMakeSymmetric(Image *img);
128 int imgGetSymmetryError(Image *img, int x, int y, int radius);
129 Image *imgPatternDifference( Image *img, Image *pat, Image *res, int x1, int y1, int x2, int y2);
130 int imgGetPixelDifference(unsigned char *p1, unsigned char *p2);
131 
132 int imgGetSumArea( Image *img, // Image to analyze
133  int x1, int y1, int x2, int y2);
134 float imgGetMeanArea( Image *img, // Image to analyze (where to search)
135  int x1, int y1, int x2, int y2); // Rectangular area of img to use
136 float imgGetMean(Image *img);
137 
138 unsigned int imgGetWidth(Image * img);
139 unsigned int imgGetHeight(Image * img);
140 void imgSetPixel(Image * img, unsigned int x, unsigned int y, unsigned char *pdata);
141 void imgSetPixelRGB(Image * img, unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b);
142 void imgSetPixelRGBA(Image * img, unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
143 
144 unsigned char * imgGetPixel(Image * img, unsigned int x, unsigned int y);
145 unsigned char * imgPixel(Image * img, unsigned int x, unsigned int y);
146 
147 void MarkImagePositionRGB(Image * img, int x, int y, unsigned char r, unsigned char g, unsigned char b);
148 void MarkImagePosition(Image * img, int x, int y);
149 
152 /* Viewer operations */
158 Viewer * viewOpen(unsigned int width, unsigned int height, const char * title);
160 
164 void viewDisplayImage(Viewer *view, Image *img);
166 
170 void viewClose(Viewer *view);
172 
175 int viewPollEvent(SDL_Event *event);
178 #endif // _EASIMAGE_H_
179 
unsigned int width
The width of the image (Number of columns)
Definition: easimage.h:58
unsigned int height
The height of the camera frame (Number of rows)
Definition: easimage.h:48
int viewPollEvent(SDL_Event *event)
Polls for currently pending events.
Definition: viewer.c:48
void quit_easimage()
Quit easimage.
Definition: util.c:58
unsigned int n_buffers
Number of allocated buffers.
Definition: easimage.h:53
Represents an image capturing device.
Definition: easimage.h:46
int imgGetSymmetryError(Image *img, int x, int y, int radius)
Evaluates simmetry error at location.
Definition: image.c:257
long int GetTime()
GetTime.
Definition: util.c:72
unsigned int height
The height of the image (Number of rows)
Definition: easimage.h:70
unsigned int format
Format identifier.
Definition: easimage.h:61
Definition: camera.c:31
Image * imgFromPPM(const char *filename)
Loads an image from a PPM image file.
Definition: image.c:119
Image * imgNew(unsigned int width, unsigned int height, unsigned short depth)
Creates a new image.
Definition: image.c:35
unsigned int width
The width of the image (Number of columns)
Definition: easimage.h:69
void viewClose(Viewer *view)
Terminates the viewer.
Definition: viewer.c:39
Stores an image.
Definition: easimage.h:57
SDL_Surface * screen
Pointer to screen surface.
Definition: easimage.h:71
int easimageAppEnd
Global termination flag.
Definition: util.c:19
Image * imgConvolution(Image *img1, Image *img2, Image *res)
Image convolution.
Definition: image.c:619
unsigned char * mem_ptr
location of image buffers
Definition: easimage.h:62
void waitTime(unsigned int milliseconds)
Delay for a given number of milliseconds.
Definition: util.c:38
float imgGetMean(Image *img)
Evaluates the pixel component mean value.
Definition: image.c:377
Image * imgFromBitmap(const char *filename)
Loads an image from a BMP image file.
Definition: image.c:81
char * name
The name of the image.
Definition: easimage.h:64
Image * imgCrop(Image *img, int x1, int y1, int x2, int y2)
Crops an image.
Definition: image.c:226
char * name
The name of the device.
Definition: easimage.h:50
int imgFindPatternArea(Image *img, Image *pattern, int x1, int y1, int x2, int y2, int *x, int *y)
Searches image area for a pattern.
Definition: image.c:396
unsigned int format
Format identifier.
Definition: easimage.h:49
int handle
The stream handle.
Definition: easimage.h:51
void imgScale(Image *img, unsigned int sfactor)
Scales an image.
Definition: image.c:180
Represents an image presenting device.
Definition: easimage.h:68
int imgSaveRAW(Image *img, char *fname)
Save RAW file.
Definition: image.c:713
Image * imgCopy(Image *img)
Creates a copy of an Image.
Definition: image.c:200
unsigned int width
The width of the camera frame (Number of columns)
Definition: easimage.h:47
unsigned int height
The height of the image (Number of rows)
Definition: easimage.h:59
void viewDisplayImage(Viewer *view, Image *img)
Displays an Image.
Definition: viewer.c:60
unsigned char * imgGetPixel(Image *img, unsigned int x, unsigned int y)
Gets pixel data.
Definition: image.c:594
void init_easimage()
Init easimage.
Definition: util.c:22
void imgDestroy(Image *img)
Destroys the image.
Definition: image.c:689
unsigned char * data
location of pixel data
Definition: easimage.h:63
int imgFindPattern(Image *img, Image *pattern, int *x, int *y)
Searches image for a pattern.
Definition: image.c:452
unsigned short int depth
The depth of the image (number of bit per pixel)
Definition: easimage.h:60
Image * imgPatternDifference(Image *img, Image *pat, Image *res, int x1, int y1, int x2, int y2)
Searches image for a pattern.
Definition: image.c:297
struct Buffer * buffers
location of image buffers
Definition: easimage.h:52
float imgGetMeanArea(Image *img, int x1, int y1, int x2, int y2)
Evaluates the pixel component mean value.
Definition: image.c:362
int imgGetSumArea(Image *img, int x1, int y1, int x2, int y2)
Evaluates the addition of pixel components.
Definition: image.c:336