定義済みのモードを使用する必要はありません。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 インストール スクリプトを再度実行するだけです)。