-
Notifications
You must be signed in to change notification settings - Fork 7
/
imgqueue.h
49 lines (44 loc) · 915 Bytes
/
imgqueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* A warpper class to make image list testing easy.
*
* @blackball ([email protected])
*/
#ifndef IMG_QUEUE_H
#define IMG_QUEUE_H
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
class ImgQueue {
public:
ImgQueue():m_fp(0), m_img(0){}
~ImgQueue(){ _release(); }
void open(const char *fname) {
_release();
m_fp = fopen(fname, "r");
if (!m_fp) {
fprintf(stderr, "Can not open file %s!", fname);
exit(0);
}
}
IplImage * nextImg(int color_or_gray ) {
if (!m_fp) return NULL;
if (m_img) {
cvReleaseImage( &m_img );
m_img = NULL;
}
if (1 == fscanf(m_fp, "%s", m_name)) {
m_img = cvLoadImage(m_name, color_or_gray & 0x1 );
}
return m_img;
}
protected:
void _release() {
if (m_fp) fclose(m_fp);
if (m_img) cvReleaseImage( &m_img );
}
private:
FILE * m_fp;
char m_name[ MAX_PATH ];
IplImage * m_img;
};
#endif