问题描述
有人知道如何在IDS摄像机上正确配置Mono12模式吗?
我尝试过is_SetColorMode方法,将每个像素的BITES设置为12,将每个像素的BYTES设置为2,依此类推。效果不好。
最后,我在IDS uEye Cockpit中完成了一个配置文件,保存了它,现在用于在python代码的开头设置摄像机。这也无济于事。
我现在遇到的问题是,要获取的图像是以〜2056 * 2056(芯片大小)的两个数组引入的。这是因为我每个像素有2个字节。但是我不知道如何将其正确转换为普通图像。
此外,即使在默认的Mono8模式下,我也会看到与IDS应用程序不同的图片。
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,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,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,pid,ueye.INT(),bts,pitch)
print(str(nRet) + ' - InquireImageMem')
array = ueye.get_data(pcImageMem,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,2)
plt.imshow(pict[:,1])
plt.subplot(1,3)
plt.imshow(pict[:,0] + pict[:,1])
plt.show()
nRet = ueye.is_ExitCamera(hCam)
解决方法
由于Mono12不是压缩格式,因此必须每个像素使用16位而不是12位。请查看手册页“颜色和内存格式”。在MONO12彩色模式下,它显示16位。
,尝试通过ueye.is_PixelClock()
命令减少pixelclock。
当我尝试将RAW12
与pixelclock= 35
(UI-3240的最大可用速度)一起使用时,图像获取命令未返回任何结果(0),就像您的情况一样。
但是一旦我降低到10MHz,图像数据通常会返回。
此图像格式与像素时钟问题也可以由IDS相机管理器检查。 当您将格式从Mono8(默认)切换为Raw12时,程序会立即显示错误消息。