123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- from pyueye import ueye
- import numpy as np
- import time
- import cv2
- import os
- from datetime import datetime
- hCam = ueye.HIDS(0)
- sensor_info = ueye.SENSORINFO()
- camera_info = ueye.CAMINFO()
- pcImageMemory = ueye.c_mem_p()
- MemID = ueye.int()
- rectAOI = ueye.IS_RECT()
- rectAOI.s32X = 0
- rectAOI.s32Y = 152
- rectAOI.s32Width = 1936
- rectAOI.s32Height = 472
- pitch = ueye.INT()
- nBitsPerPixel = ueye.INT(24)
- channels = 3
- m_nColorMode = ueye.INT()
- bytes_per_pixel = int(nBitsPerPixel / 8)
- dZoomValue = ueye.DOUBLE()
- fps = ueye.DOUBLE(30)
- Real_FPS =ueye.DOUBLE()
- exposure_value = ueye.DOUBLE(10)
- cbSizeOfParam = 8
- gpio = ueye.IO_GPIO_CONFIGURATION()
- gpio.u32Gpio = ueye.IO_GPIO_1
- gpio.u32Configuration = ueye.IS_GPIO_INPUT
- gpio.u32State = ueye.UINT()
- print("START")
- nRet = ueye.is_InitCamera(hCam, None)
- if nRet != ueye.IS_SUCCESS:
- print("is_InitCamera ERROR")
- nRet = ueye.is_SetFrameRate(hCam,fps,Real_FPS)
- if nRet != ueye.IS_SUCCESS:
- print("is_SetFrameRate ERROR")
- nRet = ueye.is_Exposure(hCam,ueye.IS_EXPOSURE_CMD_SET_EXPOSURE,exposure_value,cbSizeOfParam)
- if nRet != ueye.IS_SUCCESS:
- print("is_Exposure ERROR")
- nRet = ueye.is_GetCameraInfo(hCam, camera_info)
- if nRet != ueye.IS_SUCCESS:
- print("is_GetCameraInfo ERROR")
- nRet = ueye.is_GetSensorInfo(hCam, sensor_info)
- if nRet != ueye.IS_SUCCESS:
- print("is_GetSensorInfo ERROR")
- '''
- nRet = ueye.is_ResetToDefault(hCam)
- if nRet != ueye.IS_SUCCESS:
- print("is_ResetToDefault ERROR")
- '''
- nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB)
- if int.from_bytes(sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER:
-
- ueye.is_GetColorDepth(hCam, nBitsPerPixel, m_nColorMode)
- bytes_per_pixel = int(nBitsPerPixel / 8)
- print("IS_COLORMODE_BAYER: ", )
- print("\tm_nColorMode:", m_nColorMode)
- print("\tnBitsPerPixel:", nBitsPerPixel)
- print("\tbytes_per_pixel:", bytes_per_pixel)
- elif int.from_bytes(sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY:
-
- m_nColorMode = ueye.IS_CM_BGRA8_PACKED
- nBitsPerPixel = ueye.INT(32)
- bytes_per_pixel = int(nBitsPerPixel / 8)
- print("IS_COLORMODE_CBYCRY: ", )
- print("\tm_nColorMode: \t\t", m_nColorMode)
- print("\tnBitsPerPixel: \t\t", nBitsPerPixel)
- print("\tbytes_per_pixel: \t\t", bytes_per_pixel)
- elif int.from_bytes(sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME:
-
- m_nColorMode = ueye.IS_CM_MONO8
- nBitsPerPixel = ueye.INT(8)
- bytes_per_pixel = int(nBitsPerPixel / 8)
- print("IS_COLORMODE_MONOCHROME: ", )
- print("\tm_nColorMode: \t\t", m_nColorMode)
- print("\tnBitsPerPixel: \t\t", nBitsPerPixel)
- print("\tbytes_per_pixel: \t\t", bytes_per_pixel)
- else:
-
- m_nColorMode = ueye.IS_CM_MONO8
- nBitsPerPixel = ueye.INT(8)
- bytes_per_pixel = int(nBitsPerPixel / 8)
- print("else")
- '''
- nRet = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_SET_AOI, rectAOI, ueye.sizeof(rectAOI))
- if nRet != ueye.IS_SUCCESS:
- print("is_AOI ERROR")
- # Can be used to set the size and position of an "area of interest"(AOI) within an image
- nRet = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI))
- if nRet != ueye.IS_SUCCESS:
- print("is_AOI ERROR")
- width = rectAOI.s32Width
- height = rectAOI.s32Height
- x = rectAOI.s32X
- y = rectAOI.s32Y
- '''
- print("Now FPS :{}".format(fps))
- print("Real FPS :{}".format(Real_FPS))
- print("Exposure value : {}".format(exposure_value))
- print("Maximum image width:", width)
- print("Maximum image height:", height)
- print("Maximum image x:", x)
- print("Maximum image y:", y)
- nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID)
- if nRet != ueye.IS_SUCCESS:
- print("is_AllocImageMem ERROR")
- else:
-
- nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID)
- if nRet != ueye.IS_SUCCESS:
- print("is_SetImageMem ERROR")
- else:
-
- nRet = ueye.is_SetColorMode(hCam, m_nColorMode)
- nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT)
- if nRet != ueye.IS_SUCCESS:
- print("is_CaptureVideo ERROR")
- nRet = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch)
- if nRet != ueye.IS_SUCCESS:
- print("is_InquireImageMem ERROR")
- else:
- print("Press q to leave the programm")
- f = 1
- while nRet == ueye.IS_SUCCESS:
-
-
- array = ueye.get_data(pcImageMemory, width, height, nBitsPerPixel, pitch, copy=False)
-
-
- frame = np.reshape(array, (height.value, width.value, bytes_per_pixel))
-
- cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame)
- if cv2.waitKey(1) & 0xFF == ord('p'):
- FileParams = ueye.IMAGE_FILE_PARAMS()
- FileParams.pwchFileName = "C:\\Users\\User\\Desktop\\IDS\\" + str(f) + ".png"
- FileParams.nFileType = ueye.IS_IMG_PNG
- FileParams.ppcImageMem = None
- FileParams.pnImageID = None
- FileParams.nQuality = 75
- nRet = ueye.is_ImageFile(hCam, ueye.IS_IMAGE_FILE_CMD_SAVE, FileParams, ueye.sizeof(FileParams))
- elif cv2.waitKey(1) & 0xFF == ord('q'):
- break
- ueye.is_FreeImageMem(hCam, pcImageMemory, MemID)
- ueye.is_ExitCamera(hCam)
- cv2.destroyAllWindows()
|