0

我正在使用CMLN-13S2C-CS CCDPointGrey Systems 的相机。它使用 FlyCapture API 来抓取图像。我想抓取这些图像并使用 python 在 OpenCV 中做一些事情。

我知道以下 python 绑定:pyflycapture2。使用此绑定,我可以检索图像。但是,我无法检索彩色图像,这是相机应该能够做到的。

相机能够处理的视频模式和帧率分别为VIDEOMODE_1280x960Y8、 和FRAMERATE_15。我认为这与pixel_format我认为应该是的有关raw8

有没有人能够使用这个或任何现有的用于 flycapture 的 python 绑定来检索彩色图像?请注意,我正在使用 Linux。

4

2 回答 2

0

您不需要使用预定义的模式。该类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 安装脚本)。

于 2016-05-11T14:34:10.270 回答
-1

我正在使用与 Matlab 相同的相机,并且还遇到了“raw8”格式的问题。所以,我选择了“rgb8”,特别是“F7_RGB_644x482_Mode1”,一切都开始工作了(不确定,它应该如何看待 Python)。

PS 目前我正在尝试开始使用 Python 和 pyflycapture2,让我们看看是否能够找到解决方法。

UPD:好的,现在我知道了。:) 您(和我的)问题原因隐藏在 pyflycapture2 本身中,尤其是“Image”类定义。你可以看看这里:https ://github.com/jordens/pyflycapture2/blob/eec14acd761e89d8e63a0961174e7f5900180d54/src/flycapture2.pyx

if self.img.format == PIXEL_FORMAT_MONO8:
            dtype = np.dtype("uint8")
            stride[1] = 1
        elif self.img.format == PIXEL_FORMAT_MONO16:
            dtype = np.dtype("uint16")
            stride[1] = 2
        else:
            dtype = np.dtype("uint8")
            stride[1] = self.img.stride/self.img.cols

任何图像都将被转换为灰度,即使它最初是 RGB。因此,我们需要以某种方式更新该文件。

于 2015-11-26T15:32:43.287 回答