1
JPEG文件的尾部包含一個複雜的結構,如下列:如何使用Python解析JPEG文件中的複雜結構?
FFD8...........................
...............................
............FFD9 1C01 0000 ....
...............................
struct definations in C file are:
typedef struct
{
short wYear;
short wMonth;
short wDayOfWeek;
short wDay;
short wHour;
short wMinute;
short wSecond;
short wMilliseconds;
}SYSEMTTIME;
typedef struct
{
int nOcrResult;
char szPlateText[16];
char szPlateColor[8];
char szCarColor[8];
RECT rtPlate;
} OCR_PLATE;
typedef struct
{
unsigned int size;
unsigned char nLane[4];
unsigned char nImageFalgs[4];
unsigned int nRandom[4];
unsigned char nIndex[4];
unsigned char nImageIndex[4];
unsigned char nTotalCount[4];
unsigned char nTrigerNow[4];
unsigned char nCarSpeed[4];
unsigned char nLimitSpeed[4];
unsigned char nDelayFrame[4];
OCR_PLATE struPlate[4];
SYSTEMTIME stTime;
unsigned int szFlags;
} IMAGE_CAPTURE_INFO;
而在Python中,我一直在使用CTYPE的庫寫了一些類:
class POINT(Structure):
_fields_ = [("x", c_int),("y", c_int)]
class RECT(Structure):
_fields_ = [("left", c_int),("top", c_int),("right", c_int),
("bottom", c_int)]
class OCR_PLATE(Structure):
_fields_ = [("nOcrResult", c_int),
("szPlateText", c_char * 16),
("szPlateColor", c_char * 8),
("szCarColor", c_char * 8),
("rtPlate", RECT)]
class SYSTEMTIME(Structure):
_fields_ = [("wYear", c_short),
("wMonth", c_short),
("wDayOfWeek", c_short),
("wDay", c_short),
("wHour", c_short),
("wMinute", c_short),
("wSecond", c_short),
("wMilliseconds", c_short)]
class IMAGE_CAPTURE_INFO(Structure):
_fields_ = [("size", c_uint),
("nLane", c_ubyte * 4),
("nImageFalgs", c_ubyte * 4),
("nRandom", c_uint * 4),
("nIndex", c_ubyte * 4),
("nImageIndex", c_ubyte * 4),
("nTotalCount", c_ubyte * 4),
("nTrigerNow", c_ubyte * 4),
("nCarSpeed", c_ubyte * 4),
("nLimitSpeed", c_ubyte * 4),
("nDelayFrame", c_ubyte * 4),
("struPlate", OCR_PLATE * 4),
("stTime", SYSTEMTIME),
("szFlags", c_uint)]
但如何讀取數據從JPEG圖像文件中以上述結構的形式?