1

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图像文件中读取数据呢?

4

1 回答 1

1

您需要知道此结构在文件中的位置偏移量。
假设它在文件的末尾:

data = open("filename.jpg", "rb").read()
offset = len(data) - sizeof(IMAGE_CAPTURE_INFO)
myStructure = IMAGE_CAPTURE_INFO.from_buffer(data, offset)
于 2016-08-31T09:25:24.400 回答