|
@@ -1,118 +1,95 @@
|
|
|
-#===========================================================================#
|
|
|
-# #
|
|
|
-# Copyright (C) 2006 - 2018 #
|
|
|
-# IDS Imaging Development Systems GmbH #
|
|
|
-# Dimbacher Str. 6-8 #
|
|
|
-# D-74182 Obersulm, Germany #
|
|
|
-# #
|
|
|
-# The information in this document is subject to change without notice #
|
|
|
-# and should not be construed as a commitment by IDS Imaging Development #
|
|
|
-# Systems GmbH. IDS Imaging Development Systems GmbH does not assume any #
|
|
|
-# responsibility for any errors that may appear in this document. #
|
|
|
-# #
|
|
|
-# This document, or source code, is provided solely as an example #
|
|
|
-# of how to utilize IDS software libraries in a sample application. #
|
|
|
-# IDS Imaging Development Systems GmbH does not assume any responsibility #
|
|
|
-# for the use or reliability of any portion of this document or the #
|
|
|
-# described software. #
|
|
|
-# #
|
|
|
-# General permission to copy or modify, but not for profit, is hereby #
|
|
|
-# granted, provided that the above copyright notice is included and #
|
|
|
-# reference made to the fact that reproduction privileges were granted #
|
|
|
-# by IDS Imaging Development Systems GmbH. #
|
|
|
-# #
|
|
|
-# IDS Imaging Development Systems GmbH cannot assume any responsibility #
|
|
|
-# for the use or misuse of any portion of this software for other than #
|
|
|
-# its intended diagnostic purpose in calibrating and testing IDS #
|
|
|
-# manufactured cameras and software. #
|
|
|
-# #
|
|
|
-#===========================================================================#
|
|
|
-
|
|
|
-# Developer Note: I tried to let it as simple as possible.
|
|
|
-# Therefore there are no functions asking for the newest driver software or freeing memory beforehand, etc.
|
|
|
-# The sole purpose of this program is to show one of the simplest ways to interact with an IDS camera via the uEye API.
|
|
|
-# (XS cameras are not supported)
|
|
|
-#---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-#Libraries
|
|
|
-from ctypes import *
|
|
|
from pyueye import ueye
|
|
|
import numpy as np
|
|
|
+import time
|
|
|
import cv2
|
|
|
-import sys
|
|
|
-import ctypes
|
|
|
-import struct
|
|
|
-import threading
|
|
|
-#---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
+import os
|
|
|
+from datetime import datetime
|
|
|
|
|
|
-#Variables
|
|
|
|
|
|
-hCam = ueye.HIDS(0) #0: first available camera; 1-254: The camera with the specified camera ID
|
|
|
-sInfo = ueye.SENSORINFO()
|
|
|
-cInfo = ueye.CAMINFO()
|
|
|
+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) #24: bits per pixel for color mode; take 8 bits per pixel for monochrome
|
|
|
channels = 3 #3: channels for color mode(RGB); take 1 channel for monochrome
|
|
|
m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32
|
|
|
bytes_per_pixel = int(nBitsPerPixel / 8)
|
|
|
-formatInfo=ueye.IMAGE_FORMAT_INFO()
|
|
|
-now=ctypes.c_uint()
|
|
|
-m_pcSeqImgMem=[]
|
|
|
-m_lSeqMemId=[]
|
|
|
-nNum=ueye.INT()
|
|
|
-pcMem=ueye.c_mem_p()
|
|
|
-pcMemLast=ueye.c_mem_p()
|
|
|
-ImageFileParams=ueye.IMAGE_FILE_PARAMS()
|
|
|
-#---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+dZoomValue = ueye.DOUBLE()
|
|
|
+
|
|
|
+fps = ueye.DOUBLE(30) # set you want fps
|
|
|
+Real_FPS =ueye.DOUBLE() # get real fps
|
|
|
+
|
|
|
+exposure_value = ueye.DOUBLE(10) # set exposure value
|
|
|
+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")
|
|
|
-print()
|
|
|
|
|
|
# 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")
|
|
|
|
|
|
-ueye.is_ParameterSet(hCam,ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM,None,0)
|
|
|
+nRet = ueye.is_SetFrameRate(hCam,fps,Real_FPS)
|
|
|
+#ueye.IS_GET_DEFAULT_FRAMERATE
|
|
|
+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")
|
|
|
|
|
|
# Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to
|
|
|
-nRet = ueye.is_GetCameraInfo(hCam, cInfo)
|
|
|
+nRet = ueye.is_GetCameraInfo(hCam, camera_info)
|
|
|
if nRet != ueye.IS_SUCCESS:
|
|
|
print("is_GetCameraInfo ERROR")
|
|
|
|
|
|
# You can query additional information about the sensor type used in the camera
|
|
|
-nRet = ueye.is_GetSensorInfo(hCam, sInfo)
|
|
|
+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")
|
|
|
+'''
|
|
|
|
|
|
# Set display mode to DIB
|
|
|
nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB)
|
|
|
|
|
|
# Set the right color mode
|
|
|
-if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER:
|
|
|
+if int.from_bytes(sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER:
|
|
|
# setup the color depth to the current windows setting
|
|
|
ueye.is_GetColorDepth(hCam, nBitsPerPixel, m_nColorMode)
|
|
|
bytes_per_pixel = int(nBitsPerPixel / 8)
|
|
|
print("IS_COLORMODE_BAYER: ", )
|
|
|
- print("\tm_nColorMode: \t\t", m_nColorMode)
|
|
|
- print("\tnBitsPerPixel: \t\t", nBitsPerPixel)
|
|
|
- print("\tbytes_per_pixel: \t\t", bytes_per_pixel)
|
|
|
- print()
|
|
|
+ print("\tm_nColorMode:", m_nColorMode)
|
|
|
+ print("\tnBitsPerPixel:", nBitsPerPixel)
|
|
|
+ print("\tbytes_per_pixel:", bytes_per_pixel)
|
|
|
|
|
|
-elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY:
|
|
|
+elif int.from_bytes(sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY:
|
|
|
# for color camera models use RGB32 mode
|
|
|
- m_nColorMode = ueye.IS_CM_BGR8_PACKED
|
|
|
- nBitsPerPixel = ueye.INT(24)
|
|
|
+ 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)
|
|
|
- print()
|
|
|
|
|
|
-elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME:
|
|
|
+elif int.from_bytes(sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME:
|
|
|
# for color camera models use RGB32 mode
|
|
|
m_nColorMode = ueye.IS_CM_MONO8
|
|
|
nBitsPerPixel = ueye.INT(8)
|
|
@@ -121,7 +98,6 @@ elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMOD
|
|
|
print("\tm_nColorMode: \t\t", m_nColorMode)
|
|
|
print("\tnBitsPerPixel: \t\t", nBitsPerPixel)
|
|
|
print("\tbytes_per_pixel: \t\t", bytes_per_pixel)
|
|
|
- print()
|
|
|
|
|
|
else:
|
|
|
# for monochrome camera models use Y8 mode
|
|
@@ -129,94 +105,84 @@ else:
|
|
|
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")
|
|
|
|
|
|
-
|
|
|
-ueye.is_SetColorMode(hCam,ueye.IS_CM_BGRA8_PACKED)
|
|
|
-nBitsPerPixel=ueye.INT(32)
|
|
|
# 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
|
|
|
-
|
|
|
+width = rectAOI.s32Width
|
|
|
+height = rectAOI.s32Height
|
|
|
+x = rectAOI.s32X
|
|
|
+y = rectAOI.s32Y
|
|
|
+'''
|
|
|
# Prints out some information about the camera and the sensor
|
|
|
-print("Camera model:\t\t", sInfo.strSensorName.decode('utf-8'))
|
|
|
-print("Camera serial no.:\t", cInfo.SerNo.decode('utf-8'))
|
|
|
-print("Maximum image width:\t", width)
|
|
|
-print("Maximum image height:\t", height)
|
|
|
-print()
|
|
|
|
|
|
-#---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
+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)
|
|
|
+# ---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
-for i in range(1,5):
|
|
|
# Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel
|
|
|
- nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID)
|
|
|
- # m_pcSeqImgMem.append(pcImageMemory)
|
|
|
- # m_lSeqMemId.append(MemID)
|
|
|
- ueye.is_AddToSequence(hCam,pcImageMemory,MemID)
|
|
|
-
|
|
|
-#path=ueye.c_wchar_p()
|
|
|
-#print(type(path))
|
|
|
-#nRet = ueye.is_ParameterSet(hCam, ueye.IS_PARAMETERSET_CMD_LOAD_FILE, path, 0)
|
|
|
-
|
|
|
+nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID)
|
|
|
+if nRet != ueye.IS_SUCCESS:
|
|
|
+ print("is_AllocImageMem ERROR")
|
|
|
+else:
|
|
|
+ # Makes the specified image memory the active memory
|
|
|
+ nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID)
|
|
|
+ if nRet != ueye.IS_SUCCESS:
|
|
|
+ print("is_SetImageMem ERROR")
|
|
|
+ else:
|
|
|
+ # Set the desired color mode
|
|
|
+ nRet = ueye.is_SetColorMode(hCam, m_nColorMode)
|
|
|
+
|
|
|
# Activates the camera's live video mode (free run mode)
|
|
|
nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT)
|
|
|
if nRet != ueye.IS_SUCCESS:
|
|
|
print("is_CaptureVideo ERROR")
|
|
|
|
|
|
+# Enables the queue mode for existing image memory sequences
|
|
|
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")
|
|
|
-
|
|
|
-Count=0
|
|
|
-
|
|
|
-while(nRet == ueye.IS_SUCCESS):
|
|
|
-
|
|
|
- ueye.is_GetActSeqBuf(hCam, nNum, pcMem, pcMemLast)
|
|
|
- array = ueye.get_data(pcMemLast, width, height, nBitsPerPixel, pitch, copy=False)
|
|
|
-
|
|
|
- bytes_per_pixel = int(nBitsPerPixel / 8)
|
|
|
+# ---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
+f = 1
|
|
|
+# Continuous image display
|
|
|
+while nRet == ueye.IS_SUCCESS:
|
|
|
+ # In order to display the image in an OpenCV window we need to...
|
|
|
+ # ...extract the data of our image memory
|
|
|
+ array = ueye.get_data(pcImageMemory, width, height, nBitsPerPixel, pitch, copy=False)
|
|
|
+ # bytes_per_pixel = int(nBitsPerPixel / 8)
|
|
|
# ...reshape it in an numpy array...
|
|
|
- frame = np.reshape(array,(height.value, width.value, bytes_per_pixel))
|
|
|
- # ...resize the image by a half
|
|
|
-
|
|
|
- frame = cv2.resize(frame,(0,0),fx=0.5, fy=0.5)
|
|
|
-
|
|
|
- #---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
- #Include image data processing here
|
|
|
- if cv2.waitKey(2) & 0xFF == ord('p'):
|
|
|
- Count=Count+1
|
|
|
- ImageFileParams.pwchFileName = ueye.c_wchar_p('C:\\Users\\User\\Desktop\\test\\1.png')
|
|
|
- #ImageFileParams.pnImageID = &nID;
|
|
|
- #ImageFileParams.ppcImageMem = &pcMemory;
|
|
|
- ImageFileParams.nFileType = ueye.IS_IMG_PNG
|
|
|
- #ImageFileParams.ppcImageMem = pcMemLast;
|
|
|
- ImageFileParams.nQuality = 75
|
|
|
- nRet = ueye.is_ImageFile(hCam, ueye.IS_IMAGE_FILE_CMD_SAVE, ImageFileParams, ueye.sizeof(ImageFileParams));
|
|
|
- print(Count)
|
|
|
- print(nRet)
|
|
|
-#---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
- #...and finally display it
|
|
|
+ frame = np.reshape(array, (height.value, width.value, bytes_per_pixel))
|
|
|
+ #frame = cv2.resize(frame, (800, 600), fx=0.5, fy=0.5)
|
|
|
cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame)
|
|
|
-
|
|
|
- # Press q if you want to end the loop
|
|
|
- if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
|
+ 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
|
|
|
-#---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+# ---------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
# Releases an image memory that was allocated using is_AllocImageMem() and removes it from the driver management
|
|
|
ueye.is_FreeImageMem(hCam, pcImageMemory, MemID)
|
|
|
-
|
|
|
-
|
|
|
# Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera
|
|
|
ueye.is_ExitCamera(hCam)
|
|
|
-
|
|
|
# Destroys the OpenCv windows
|
|
|
-cv2.destroyAllWindows()
|
|
|
-
|
|
|
-print()
|
|
|
-print("END")
|
|
|
+cv2.destroyAllWindows()
|