123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- from ctypes import *
- from pyueye import ueye
- import numpy as np
- import cv2
- import sys
- import ctypes
- import struct
- import threading
- import time
- import datetime
- hCam = ueye.HIDS(0)
- sInfo = ueye.SENSORINFO()
- cInfo = ueye.CAMINFO()
- pcImageMemory = ueye.c_mem_p()
- MemID = ueye.int()
- rectAOI = ueye.IS_RECT()
- pitch = ueye.INT()
- nBitsPerPixel = ueye.INT(24)
- channels = 3
- m_nColorMode = ueye.INT()
- 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()
- print("START")
- 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_GetCameraInfo(hCam, cInfo)
- if nRet != ueye.IS_SUCCESS:
- print("is_GetCameraInfo ERROR")
- nRet = ueye.is_GetSensorInfo(hCam, sInfo)
- if nRet != ueye.IS_SUCCESS:
- print("is_GetSensorInfo ERROR")
- nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB)
- if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER:
-
- ueye.is_GetColorDepth(hCam, nBitsPerPixel, m_nColorMode)
- bytes_per_pixel = int(nBitsPerPixel / 8)
-
-
-
-
-
- elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY:
-
- m_nColorMode = ueye.IS_CM_BGR8_PACKED
- nBitsPerPixel = ueye.INT(24)
- bytes_per_pixel = int(nBitsPerPixel / 8)
-
-
-
-
-
- elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME:
-
- m_nColorMode = ueye.IS_CM_MONO8
- nBitsPerPixel = ueye.INT(8)
- bytes_per_pixel = int(nBitsPerPixel / 8)
-
-
-
-
-
- else:
-
- m_nColorMode = ueye.IS_CM_MONO8
- nBitsPerPixel = ueye.INT(8)
- bytes_per_pixel = int(nBitsPerPixel / 8)
- print("else")
- ueye.is_SetColorMode(hCam,ueye.IS_CM_BGRA8_PACKED)
- nBitsPerPixel=ueye.INT(32)
- 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
- for i in range(1,5):
- nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID)
-
-
- ueye.is_AddToSequence(hCam,pcImageMemory,MemID)
-
- 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")
- 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)
-
- frame = np.reshape(array,(height.value, width.value, bytes_per_pixel))
-
- frame = cv2.resize(frame,(0,0),fx=0.5, fy=0.5)
-
-
- Count = Count + 1
- '''
- 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)
- '''
-
- cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame)
- time.sleep(0.5)
- ImageFileParams.pwchFileName = ueye.c_wchar_p('C:\\Users\\User\\Desktop\\tfcoffebean\\test\\1.png')
- ImageFileParams.nFileType = ueye.IS_IMG_PNG
- ImageFileParams.nQuality = 75
- nRet = ueye.is_ImageFile(hCam, ueye.IS_IMAGE_FILE_CMD_SAVE, ImageFileParams, ueye.sizeof(ImageFileParams));
- print(Count)
- print(nRet)
-
-
-
- ueye.is_FreeImageMem(hCam, pcImageMemory, MemID)
- ueye.is_ExitCamera(hCam)
- cv2.destroyAllWindows()
- print("END")
|