ctypes中的回调函数python3只运行一次

时间:2016-01-08 15:43:38

标签: python c++ callback ctypes pyqt5

我们正在开发一种医疗相机,可生成发送到python Qt应用程序的图像(每秒25帧)。我跑进了一堵砖墙,试图从相机中获取一系列图像。每个帧由回调函数处理,然后由帧处理器处理。

我们在Windows 7 64位和python3

下运行

我们有以下c ++标题:

DC_API  signed int Start(const ImageConfig * cfg, 
                  void (*NewImage)(const char * image, unsigned int width, unsigned int height, unsigned int frameNumber, unsigned long long frameTime));

我在python中使用的是:

def __init__(self, frame_processor ):
    self.callback_frame_processor = frame_processor
    def new_image(image, width, height, framenbr, frametime):
        self.width = width
        self.height = height
        self.frametime = frametime
        self.framenr = framenbr
        self.callback_frame_processor(image)
    self.new_image_function = ctypes.CFUNCTYPE( None, ctypes.POINTER(ctypes.c_char), ctypes.c_int,
                                       ctypes.c_int, ctypes.c_int, ctypes.c_longlong )
    self.callback_function = self.new_image_function(new_image)

帧处理器是:

def start_grabbing_frames(self):
    f = self._preparecall('Start')
    image_config_struct, image_config_pointer = self._fill_image_config()
    f.argtypes = [image_config_pointer, self.new_image_function]
    return self.process_errorcodes(f(ctypes.byref(image_config_struct), self.callback_function))

帧处理器是:

def camera_callback(self, raw_image, width, height):
    qt_image = QImage(raw_image, width, height, QImage.Format.RGB888)
    qpixmap = QPixmap(width, height)
    pix = qpixmap.fromImage(qt_image)
    self.emit(pix)

问题是图像似乎不是有效帧(len(raw_image)是13036022而宽度是2208,高度是1648)。这导致挂起的应用程序没有显示图像。

0 个答案:

没有答案