Search code examples
pythonidsueye

Configure Mono12 mode at IDS camera via python uEye


Does anyone know how to configure properly Mono12 mode at IDS camera?

I've tried the is_SetColorMode method, setting the BITES per pixel to 12 and BYTES per pixel to 2 and so on. It doesn't work that well.

Finally I've done a config file in IDS uEye Cockpit, saved it and now use to set the camera up in the beginning of the python code. It doesn't help also.

The problem I'm having now is that the image I'm getting is introduced in two arrays of ~2056*2056 (Chip size). It happens because I have 2 Bytes per pixel. But I don't know how to convert it properly into normal image.

In addition even in Mono8 mode which is default I see a picture different from the one I get in IDS app.

Here is the code (I can also give the config file):

import matplotlib.pyplot as plt
import numpy as np
import cv2
import sys
import pyueye.ueye as ueye
import time

hCam = ueye.HIDS(0)
# Starts the driver and establishes the connection to the camera
nRet = ueye.is_InitCamera(hCam, None)
if nRet != ueye.IS_SUCCESS:
    print("is_InitCamera ERROR")

conf_file = 'camera_config_mono12.ini'

nRet = ueye.is_ParameterSet(hCam,
                            ueye.INT(2),
                            ueye.wchar_p(conf_file),
                            ueye.sizeof(ueye.INT(2)))
print(str(nRet) + ' - ParameterSet')

nRet = ueye.is_SetColorMode(hCam, ueye.IS_CM_MONO12)
print(str(nRet) + ' - SetColorMode')
BitesPerPix = ueye.INT(12)
BytesPerPixel = 2

nRet = ueye.is_SetDisplayMode(hCam, ueye.INT(1))
print(str(nRet) + ' - SetDisplayMode')

nRet = ueye.is_SetFrameRate(hCam, ueye.c_double(1), ueye.c_double())
print(str(nRet) + ' - SetFrameRate')

exp_time = ueye.c_void_p(200)
nRet = ueye.is_Exposure(hCam, ueye.INT(12), exp_time, 8)
print(str(nRet) + ' - Exposure')

rectAOI = ueye.IS_RECT()
nRet = ueye.is_AOI(hCam, ueye.INT(2), rectAOI, ueye.sizeof(rectAOI))
print(str(nRet) + ' - AOI')

save_file = 'C:\\Users\\novoks\\Desktop\\emva_tests\\ids\\saved_conf.ini'
nRet = ueye.is_ParameterSet(hCam,
                            ueye.INT(4),
                            ueye.wchar_p(save_file),
                            ueye.sizeof(ueye.INT(4)))

pcImageMem = ueye.c_mem_p()
pid = ueye.c_int()
nRet = ueye.is_AllocImageMem(hCam,
                             rectAOI.s32Width,
                             rectAOI.s32Height,
                             BitesPerPix,
                             pcImageMem,
                             pid)
print(str(nRet) + ' - AllocImageMem')

nRet = ueye.is_SetImageMem(hCam, pcImageMem, pid)
print(str(nRet) + ' - SetImageMem')

nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT)
print(str(nRet) + ' - CaptureVideo')

time.sleep(1)

#nRet = ueye.is_FreezeVideo(hCam, ueye.INT(0))
#print(str(nRet) + ' - FreezeVideo')

bts = ueye.INT()
pitch = ueye.INT()
nRet = ueye.is_InquireImageMem(hCam,
                               pcImageMem,
                               pid,
                               ueye.INT(),
                               ueye.INT(),
                               bts,
                               pitch)
print(str(nRet) + ' - InquireImageMem')

array = ueye.get_data(pcImageMem,
                      rectAOI.s32Width,
                      rectAOI.s32Height,
                      BitesPerPix,
                      pitch,
                      copy=False)
print(str(nRet) + ' - get_data')

pict = np.reshape(array,
                  (rectAOI.s32Height.value,
                   rectAOI.s32Width.value,
                   BytesPerPixel))

plt.figure(figsize=[12,5])

plt.subplot(1,3,1)
plt.imshow(pict[:,:,0])

plt.subplot(1,3,2)
plt.imshow(pict[:,:,1])

plt.subplot(1,3,3)
plt.imshow(pict[:,:,0] + pict[:,:,1])

plt.show()

nRet = ueye.is_ExitCamera(hCam)

Solution

  • You have to use 16 Bits per pixel instead of 12 since Mono12 is not a packed format. Have a look at the manual page "Color and memory formats". There it says 16 bits when in MONO12 color mode.