jordens / pyflycapture2

python bindings for the flycapture v2 api (libflycapture-2c)
37 stars 31 forks source link

RBG16 to Array #27

Open DPastl opened 7 years ago

DPastl commented 7 years ago

Hello,

I've been attempting to add the ability to convert to 16bit RGB values from RAW16bit images. Here's my code thus far:

def __array__(self):
    cdef np.ndarray r
    cdef np.npy_intp shape[3]
    cdef np.npy_intp stride[3]
    cdef np.dtype dtype
    fmt = self.fmt or self.img.format
    ndim = 2
    if fmt == PIXEL_FORMAT_MONO8 or fmt == PIXEL_FORMAT_RAW8:
        dtype = np.dtype("uint8")
        stride[1] = 1
    elif fmt == PIXEL_FORMAT_MONO16 or fmt == PIXEL_FORMAT_RAW16:
        dtype = np.dtype("uint16")
        stride[1] = 2
    elif fmt == PIXEL_FORMAT_RGB8 or fmt == PIXEL_FORMAT_444YUV8:
        dtype = np.dtype("uint8")
        ndim = 3
        stride[1] = 3
        stride[2] = 1
        shape[2] = 3
    elif fmt == PIXEL_FORMAT_RGB16:
        dtype = np.dtype("uint16")
        ndim = 3
        stride[1] = 6
        stride[2] = 2
        shape[2] = 3
    elif fmt == PIXEL_FORMAT_422YUV8:
        dtype = np.dtype("uint8")
        ndim = 3
        stride[1] = 2
        stride[2] = 1
        shape[2] = 2
    else:
        dtype = np.dtype("uint8")
        stride[1] = self.img.stride/self.img.cols

This isn't quite working out, I'm ending up with weird images. Do I perhaps have the stride or shape incorrect?

jordens commented 4 years ago

Have you figured this one out or found help somewhere? I don't have access to a suitable camera or know what the dataformat is and how to transform it.