个人对编程相当陌生,我正在尝试使用 python 的 pyueye 模块从 IDS 相机保存高 mp 图像。 我的代码可以保存图像,但问题是它将图像保存为 4192x3104 内的 1280x720 图像
我不知道为什么它将小图像保存在较大的文件中,并询问是否有人知道我做错了什么以及如何修复它,以便图像是整个 4192x3104
from pyueye import ueye
import ctypes
hcam = ueye.HIDS(0)
pccmem = ueye.c_mem_p()
memID = ueye.c_int()
hWnd = ctypes.c_voidp()
ueye.is_InitCamera(hcam, hWnd)
ueye.is_SetDisplayMode(hcam, 0)
sensorinfo = ueye.SENSORINFO()
ueye.is_GetSensorInfo(hcam, sensorinfo)
ueye.is_AllocImageMem(hcam, sensorinfo.nMaxWidth, sensorinfo.nMaxHeight,24, pccmem, memID)
ueye.is_SetImageMem(hcam, pccmem, memID)
ueye.is_SetDisplayPos(hcam, 100, 100)
nret = ueye.is_FreezeVideo(hcam, ueye.IS_WAIT)
print(nret)
FileParams = ueye.IMAGE_FILE_PARAMS()
FileParams.pwchFileName = "python-test-image.bmp"
FileParams.nFileType = ueye.IS_IMG_BMP
FileParams.ppcImageMem = None
FileParams.pnImageID = None
nret = ueye.is_ImageFile(hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, FileParams, ueye.sizeof(FileParams))
print(nret)
ueye.is_FreeImageMem(hcam, pccmem, memID)
ueye.is_ExitCamera(hcam)
图像的大小取决于相机的传感器尺寸。通过打印
sensorinfo.nMaxWidth
和sensorinfo.nMaxHeight
,您将获得相机捕获的图像的最大尺寸。我认为这取决于相机的型号。对我来说是 2056x1542。
您能详细说明一下问题的最后一句吗?
如果有人仍然想知道如何自动设置正确的高度和宽度,这是我的解决方案:
from pyueye import ueye
import ctypes
hcam = ueye.HIDS(0)
pccmem = ueye.c_mem_p()
memID = ueye.c_int()
hWnd = ctypes.c_voidp()
rectAOI = ueye.IS_RECT()
ueye.is_InitCamera(hcam, hWnd)
nRet = ueye.is_AOI(
hcam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)
)
width = int(rectAOI.s32Width)
height = int(rectAOI.s32Height)
ueye.is_SetDisplayMode(hcam, 0)
ueye.is_AllocImageMem(hcam, width, height, 24, pccmem, memID)
ueye.is_SetImageMem(hcam, pccmem, memID)
ueye.is_SetDisplayPos(hcam, 100, 100)
nret = ueye.is_FreezeVideo(hcam, ueye.IS_WAIT)
FileParams = ueye.IMAGE_FILE_PARAMS()
FileParams.pwchFileName = "python-test-image.bmp"
FileParams.nFileType = ueye.IS_IMG_BMP
FileParams.ppcImageMem = None
FileParams.pnImageID = None
nret = ueye.is_ImageFile(
hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, FileParams, ueye.sizeof(FileParams)
)
ueye.is_FreeImageMem(hcam, pccmem, memID)
ueye.is_ExitCamera(h
cam)
我按照 IDS 团队给出的示例进行操作,此处。