Пример #1
0
    def next(self):
        r = lib.mjpg_next_head(self.m)
        if r == lib.ERROR_EOF:
            raise StopIteration
        if r != lib.OK:
            raise UnsupportedFormatError
        if self.channels == 1:
            shape = (self.m.height, self.m.width)
        else:
            shape = (self.m.height, self.m.width, self.channels)
        img = Frame(shape, 'B')
        if img.__array_interface__['strides'] is not None:
            raise UnsupportedFormatError
        self.m.pixels = ffi.cast('unsigned char *',
                                 img.__array_interface__['data'][0])

        r = lib.mjpg_next_data(self.m)
        if r == lib.ERROR_EOF:
            raise StopIteration
        if r != lib.OK:
            raise UnsupportedFormatError

        # img = img.reshape(shape).view(type=Frame)
        img.timestamp = self.m.timestamp_sec + self.m.timestamp_usec / 1000000.0
        img.systime = img.timestamp
        img.index = self.fcnt
        self.fcnt += 1
        return img
Пример #2
0
def jpg_info(filename):
    """
    Reads a single jpeg image from the file *filename* and extracts the Axis user data header.
    The information it contains is returned as a dict with the keys "hwid", "serial_numer" and
    "firmware_version".
    """
    if sys.version_info > (3, ):
        filename = bytes(filename, "utf8")
    m = ffi.new("struct mjpg *")
    r = lib.mjpg_open(m, filename, lib.IMTYPE_GRAY, lib.IMORDER_PLANAR)
    lib.mjpg_next_head(m)
    res = {
        'hwid': ffi.string(m.hwid),
        'serial_number': ffi.string(m.serial),
        'firmware_version': ffi.string(m.firmware),
        'timestamp': m.timestamp_sec + m.timestamp_usec / 1000000.0
    }
    lib.mjpg_close(m)
    return res
Пример #3
0
    def decode_frame(self, frm, pixels, pts, grey):
        if frm.len == 0:
            return 0
        m = mjpg_ffi.new("struct mjpg *")
        if grey:
            r = mjpg_lib.mjpg_open_buffer(m, frm.data, frm.len, mjpg_lib.IMTYPE_GRAY, mjpg_lib.IMORDER_INTERLEAVED)
        else:
            r = mjpg_lib.mjpg_open_buffer(m, frm.data, frm.len, mjpg_lib.IMTYPE_RGB, mjpg_lib.IMORDER_INTERLEAVED)
        if r != mjpg_lib.OK:
            raise IOError("Failed to decode frame")

        if mjpg_lib.mjpg_next_head(m) != mjpg_lib.OK:
            return 0
        m.pixels = mjpg_ffi.cast('unsigned char *', pixels)
        if mjpg_lib.mjpg_next_data(m) != mjpg_lib.OK:
            return 0
        pts[0] = m.timestamp_sec * 1000000 + m.timestamp_usec
        mjpg_lib.mjpg_close(m)

        return 1
Пример #4
0
    def next(self):
        r = lib.mjpg_next_head(self.m)
        if r != lib.OK:
            raise StopIteration
        if self.channels == 1:
            shape = (self.m.height, self.m.width)
        else:
            shape = (self.m.height, self.m.width, self.channels)
        img = Frame(shape, 'B')
        assert img.__array_interface__['strides'] is None
        self.m.pixels = ffi.cast('unsigned char *', img.__array_interface__['data'][0])

        r = lib.mjpg_next_data(self.m)
        if r != lib.OK:
            raise StopIteration

        # img = img.reshape(shape).view(type=Frame)
        img.timestamp = self.m.timestamp_sec + self.m.timestamp_usec / 1000000.0
        img.systime = img.timestamp
        img.index = self.fcnt
        self.fcnt += 1
        return img