您不需要使用预定义的模式。该类Context
具有set_format7_configuration(mode, x_offset, y_offset, width, height, pixel_format)
您可以使用自定义设置的方法。使用它,您至少可以更改抓取图像的分辨率。使用示例:
c.set_format7_configuration(fc2.MODE_0, 320, 240, 1280, 720, fc2.PIXEL_FORMAT_MONO8)
至于上色问题。到目前为止,我已经设法使用PIXEL_FORMAT_RGB8
和修改Image
类来获得彩色图像flycapture2.pyx
,如下所示:
def __array__(self):
cdef np.ndarray r
cdef np.npy_intp shape[3] # From 2 to 3
cdef np.dtype dtype
numberofdimensions = 2 # New variable
if self.img.format == PIXEL_FORMAT_MONO8:
dtype = np.dtype("uint8")
elif self.img.format == PIXEL_FORMAT_MONO16:
dtype = np.dtype("uint16")
elif self.img.format == PIXEL_FORMAT_RGB8: # New condition
dtype = np.dtype("uint8")
numberofdimensions = 3
shape[2] = 3
else:
dtype = np.dtype("uint8")
Py_INCREF(dtype)
shape[0] = self.img.rows
shape[1] = self.img.cols
# nd value (numberofdimensions) was always 2; stride set to NULL
r = PyArray_NewFromDescr(np.ndarray, dtype,
numberofdimensions, shape, NULL,
self.img.pData, np.NPY_DEFAULT, None)
r.base = <PyObject *>self
Py_INCREF(self)
return r
这段代码很可能不是完美无缺的(即我删除了stride
这些东西),原因很简单,我对 C 和 Cython 的经验几乎为零,但这样我至少设法获得了一个彩色框架(现在正在尝试获得工作PIXEL_FORMAT_RAW8
)。
提醒一下:这flycapture2.pyx
是一个 Cython 文件,因此您需要重新编译它才能使用它(我只是再次运行 pyflycap2 安装脚本)。