def saveImage(self): ueye.is_AllocImageMem(self.hcam, self.sensorinfo.nMaxWidth, self.sensorinfo.nMaxHeight, 24, self.pccmem, self.memID) ueye.is_SetImageMem(self.hcam, self.pccmem, self.memID) ueye.is_SetDisplayPos(self.hcam, 100, 100) self.nret = ueye.is_FreezeVideo(self.hcam, ueye.IS_WAIT) self.rawImageTimeStamp = datetime.datetime.now() self.imageTimeStamp = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S') self.imageName = 'imagem_%s.jpg' % self.imageTimeStamp self.imagePath = self.operationConfigs['savingDirectory'] + self.imageName # self.imagePath = self.operationConfigs['savingDirectory'] + "tmp.jpg" self.FileParams = ueye.IMAGE_FILE_PARAMS() self.FileParams.pwchFileName = self.imagePath self.FileParams.nFileType = ueye.IS_IMG_BMP self.FileParams.ppcImageMem = None self.FileParams.pnImageID = None self.nret = ueye.is_ImageFile(self.hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, self.FileParams, ueye.sizeof(self.FileParams)) ueye.is_FreeImageMem(self.hcam, self.pccmem, self.memID) #sleep(.01) #ueye.is_ExitCamera(self.hcam) self.image = np.uint8(ndimage.imread(self.imagePath, flatten=True)) self.image = self.crop_end(self.image, 0, 100)
def init_cam(hcam): # get fps # hcam_fps = is_GetFramesPerSecond(hcam, None) # set color mode ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) # set region of interest rect_aoi = ueye.IS_RECT() rect_aoi.s32X = ueye.int(0) rect_aoi.s32Y = ueye.int(0) rect_aoi.s32Width = ueye.int(width) rect_aoi.s32Height = ueye.int(height) ueye.is_AOI(hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) # allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) ueye.is_SetImageMem(hcam, mem_ptr, mem_id) # continuous capture to memory ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) return mem_ptr
def init_cam(hcam): # get fps # hcam_fps = is_GetFramesPerSecond(hcam, None) # set color mode ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) # set region of interest rect_aoi = ueye.IS_RECT() rect_aoi.s32X = ueye.int(0) rect_aoi.s32Y = ueye.int(0) rect_aoi.s32Width = ueye.int(width) rect_aoi.s32Height = ueye.int(height) ueye.is_AOI(hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) # # # set parameters, see ids doc for parameter setting flow chart # ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, exp, ueye.sizeof(pclock)) # pclock = ueye.int(220) # ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, pclock, ueye.sizeof(pclock)) # # expo_rng = ueye.is_Exposure(hcam, IS_EXPOSURE_CMD_GET_CAPS, ncap, size(ncap)) # ftime_rng = ueye.is_GetFrameTimeRange() # expo_rng = (expo_rng[0], max(expo_rng[1], ftime_rng[1])) # # fps_actual = ueye.cdouble() # ueye.is_SetFrameRate(hcam, ueye.cdouble(fps_set), byref(fps_actual)) # # exp_cap = ueye.uint32() # ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_GET_EXPOSURE_RANGE, ueye.byref(exp_cap), ueye.sizeof(exp_cap)) # exp_cur = ueye.cdouble() # in s # ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_SET_EXPOSURE, ueye.byref(exp_cur), ueye.sizeof(exp_cur)) # ueye.is_SetGainBoost() # ueye.is_Gamma() # ueye.is_SetHWGainFactor() # # allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) ueye.is_SetImageMem(hcam, mem_ptr, mem_id) # continuous capture to memory ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) return mem_ptr
def allocateMemory(self): # Allocates an image memory for an image having its dimensions defined by self.width and height and its color depth defined by self.nBitsPerPixel nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.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(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR")
def allocate_memory(self): ''' Allocates memory on the PC and camera ''' #allocate memory self.width = 2048 self.height = 1088 c_width = ctypes.c_int(self.width) c_height = ctypes.c_int(self.height) c_pixel_bits = ctypes.c_int(self.color_mode.bits_per_pixel) #the starting memory address for the image, will be returned self.ppcImgMem = pue.c_mem_p() #the ID for the allocated image, will be returned self.pid = ctypes.c_int() #allocate memory for an image err = pue.is_AllocImageMem(self.cam, c_width, c_height, c_pixel_bits, self.ppcImgMem, self.pid) if err != pue.IS_SUCCESS: raise CameraException(self.cam, 'ueye>allocate_memory>', err) # make the image memory 'active' err = pue.is_SetImageMem(self.cam, self.ppcImgMem, self.pid) if err != pue.IS_SUCCESS: raise CameraException(self.cam, 'ueye>allocate_memory>', err) #create an array in python to which to copy the image self.image_data = np.zeros( (self.height, self.width, self.color_mode.channels), dtype=self.color_mode.dtype)
def __init__(self, _camID): self.camID=_camID self.vc = ueye.HIDS(_camID) if not (ueye.is_InitCamera(self.vc, None)==0): raise ValueError('Failed to open camera') #reserve memory self.mem_size = self.getMaxSize() ueye.is_AllocImageMem(self.vc, self.mem_size[0], self.mem_size[1],24,self.mem_ptr, self.mem_id) #set active memory region ueye.is_SetImageMem(self.vc, self.mem_ptr, self.mem_id) #continuous capture to memory ueye.is_CaptureVideo(self.vc, ueye.IS_DONT_WAIT)
def grabanimage(): camera_port = 0 ramp_frames = 40 camera = cv2.VideoCapture(camera_port) ################## original (access camera thru cv2) ########################## # def get_image(): # retval, im = camera.read() # return im # # for i in xrange(ramp_frames): # temp = get_image() # print("Taking image...") ## Take the actual image we want to keep # camera_capture = get_image() # file = "USBtemp.png" ## A nice feature of the imwrite method is that it will automatically choose the ## correct format based on the file extension you provide. Convenient! # cv2.imwrite(file, camera_capture) ############# reading from IDS camera (added 6/1/19 by Abner) ################# def get_image(w, h): im = ueye.get_data(mem_ptr, w, h, bitspixel, lineinc, copy=True) return im # init camera hcam = ueye.HIDS(0) initTrigger = ueye.is_InitCamera(hcam, None) # load camera parameters memory = ueye.int(128) # cameraSettingFile = ueye.wchar_p('/media/pi/USB30FD/Frostad Research Group/Biofilm Project/Code/FINAL_Biofilm Project.ini') ret = ueye.is_ParameterSet(hcam, ueye.IS_PARAMETERSET_CMD_LOAD_FILE, cameraSettingFile, memory) # set color mode ret = ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) # set width and height -- FIND FUNCTION TO OUTPUT IMAGE RESOLUTION width = 2560 height = 1920 # allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() bitspixel = 24 # for colormode = IS_CM_BGR8_PACKED ret = ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) # set active memory region ret = ueye.is_SetImageMem(hcam, mem_ptr, mem_id) # continuous capture to memory ret = ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) # get data from camera and display lineinc = width * int((bitspixel + 7) / 8) for i in xrange(ramp_frames): temp = get_image(width, height) print("Taking image...") # Take the actual image we want to keep camera_capture = get_image(width, height) file = "USBtemp.png"
def setMemroyForVideoCapture(self): nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.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(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
def Init_Cam(width=640, heigth=480, gain_boost=1): """inits the uEye camera""" # inits next available cam cam = ueye.HIDS(0) ueye.is_InitCamera(cam, None) ueye.is_EnableAutoExit(cam, ueye.IS_ENABLE_AUTO_EXIT) # sets the Colourmode of the camera ueye.is_SetColorMode(cam, ueye.IS_CM_SENSOR_RAW8) # sets the trigger ret = ueye.is_SetExternalTrigger(cam, ueye.IS_SET_TRIGGER_SOFTWARE) mode = ueye.int(0) # sets the blacklevel ueye.is_Blacklevel(cam, ueye.IS_BLACKLEVEL_CMD_SET_MODE, mode, ueye.sizeof(mode)) # sets the size of the image rectAOI = ueye.IS_RECT() rectAOI.s32X = 44 rectAOI.s32Y = 0 rectAOI.s32Width = 480 rectAOI.s32Height = 480 ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_SET_AOI, rectAOI, ueye.sizeof(rectAOI)) # allocates memory with given size width = ueye.int(width) heigth = ueye.int(heigth) bitspixel = ueye.int(8) pcImgMem = ueye.c_mem_p() pid = ueye.int() ueye.is_AllocImageMem(cam, 480, heigth, bitspixel, pcImgMem, pid) # sets the image memory as active ueye.is_SetImageMem(cam, pcImgMem, pid) # activates video mode ueye.is_CaptureVideo(cam, ueye.IS_DONT_WAIT) # sets gain boost mode if gain_boost == 1: ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_ON) else: ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_OFF) return cam, ret, pcImgMem, pid
def show_image(self): nRet = ueye.is_InitCamera(self.h_cam, None) nRet = ueye.is_SetDisplayMode(self.h_cam, ueye.IS_SET_DM_DIB) nRet = ueye.is_AOI(self.h_cam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height nRet = ueye.is_AllocImageMem(self.h_cam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) nRet = ueye.is_SetImageMem(self.h_cam, self.pcImageMemory, self.MemID) nRet = ueye.is_SetColorMode(self.h_cam, self.ColorMode) nRet = ueye.is_CaptureVideo(self.h_cam, ueye.IS_DONT_WAIT) nRet = ueye.is_InquireImageMem(self.h_cam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) while nRet == ueye.IS_SUCCESS: array = ueye.get_data(self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=False) frame = np.reshape( array, (self.height.value, self.width.value, self.bytes_per_pixel)) frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5) size = (self.height, self.width) new_camera_matrix, roi = cv2.getOptimalNewCameraMatrix( self.camera_matrix, self.dist_coeff, size, 1, size) dst = cv2.undistort(frame, self.camera_matrix, self.dist_coeff, None, new_camera_matrix) x, y, w, h = roi self.dst = dst[y:y + h, x:x + w] self.detect_colors() self.extrinsic_calibration() cv2.imshow("camera", self.dst) if cv2.waitKey(1) & 0xFF == ord('q'): break elif cv2.waitKey(1) & 0xFF == ord('t'): cv2.imwrite("/home/lennart/dorna/camera/images/gps.bmp", self.dst) elif cv2.waitKey(100) & 0xFF == ord('l'): self.found_container = False self.container_world_position.clear() print("Behälterposition zurückgesetzt") ueye.is_FreeImageMem(self.h_cam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.h_cam) cv2.destroyAllWindows()
def saveImage(self): try: time1 = datetime.datetime.now() ueye.is_AllocImageMem(self.hcam, self.sensorinfo.nMaxWidth, self.sensorinfo.nMaxHeight, 24, self.pccmem, self.memID) ueye.is_SetImageMem(self.hcam, self.pccmem, self.memID) ueye.is_SetDisplayPos(self.hcam, 100, 100) self.nret = ueye.is_FreezeVideo(self.hcam, ueye.IS_WAIT) self.imageTimeStamp = datetime.datetime.now().strftime( '%Y_%m_%d_%H_%M_%S') self.imageName = 'imagem_%s.jpg' % self.imageTimeStamp self.imagePath = self.operationConfigs[ 'savingDirectory'] + self.imageName self.FileParams = ueye.IMAGE_FILE_PARAMS() self.FileParams.pwchFileName = self.imagePath self.FileParams.nFileType = ueye.IS_IMG_BMP self.FileParams.ppcImageMem = None self.FileParams.pnImageID = None self.nret = ueye.is_ImageFile(self.hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, self.FileParams, ueye.sizeof(self.FileParams)) ueye.is_FreeImageMem(self.hcam, self.pccmem, self.memID) sleep(.01) ueye.is_ExitCamera(self.hcam) time2 = datetime.datetime.now() elapsed_time = time2 - time1 logging.info('Saved: {}! Elasped time (ms): {}'.format( self.imageName, elapsed_time.microseconds / 1000)) self.pijuice.status.SetLedBlink('D2', 2, [0, 255, 0], 50, [0, 255, 0], 50) sleep(.1) self.pijuice.status.SetLedState('D2', [0, 0, 0]) except: logging.warning('NOT SAVED: {}!\n'.format(self.imageName)) self.pijuice.status.SetLedBlink('D2', 2, [255, 0, 0], 50, [255, 0, 0], 50) sleep(.1) self.pijuice.status.SetLedState('D2', [0, 0, 0]) pass
def alloc_single(self): rect = self.get_aoi() bpp = get_bits_per_pixel(self.get_colormode()) buff = ImageBuffer() ueye.is_AllocImageMem(self.h_cam, rect.width, rect.height, bpp, buff.mem_ptr, buff.mem_id) check(ueye.is_SetImageMem(self.h_cam, buff.mem_ptr, buff.mem_id)) return buff
def alloc(self, h_cam): rect_aoi = ueye.IS_RECT() memory_id = ueye.int() memory_pointer = ueye.c_mem_p() bits_per_pixel = 8 ueye.is_AOI(h_cam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) ueye.is_AllocImageMem(h_cam, rect_aoi.s32Width, rect_aoi.s32Height, bits_per_pixel, memory_pointer, memory_id) ueye.is_SetImageMem(h_cam, memory_pointer, memory_id) self.img_data.memory_pointer = memory_pointer self.img_data.memory_id = memory_id self.img_data.width = rect_aoi.s32Width self.img_data.height = rect_aoi.s32Height self.img_data.bits_per_pixel = bits_per_pixel ueye.is_AllocImageMem(h_cam, rect_aoi.s32Width, rect_aoi.s32Height, 24, self.converted_memory_pointer, self.converted_memory_id)
def __init__(self): super(CamDialog, self).__init__() loadUi('cam.ui', self) self.image=None self.roi_color=None self.startButton.clicked.connect(self.start_webcam) self.stopButton.clicked.connect(self.stop_webcam) # self.detectButton.setCheckable(True) # self.detectButton.toggled.connect(self.detect_webcam_face) self.face_Enabled=False self.faceCascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') self.hCam = ueye.HIDS(0) # 0: first available camera; 1-254: The camera with the specified camera ID self.sInfo = ueye.SENSORINFO() self.cInfo = ueye.CAMINFO() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() self.rectAOI = ueye.IS_RECT() self.pitch = ueye.INT() self.nBitsPerPixel = ueye.INT(24) # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome self.channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome self.m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.nRet = ueye.is_InitCamera(self.hCam, None) self.nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo) self.nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo) self.nRet = ueye.is_ResetToDefault(self.hCam) self.nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) ueye.is_GetColorDepth(self.hCam, self.nBitsPerPixel, self.m_nColorMode) self.nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height self.nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) self.nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) self.nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) self.nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) self.nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) self.xp=[] self.yp=[] self.lxp=[] self.lyp = [] self.rxp = [] self.ryp = [] self.sx = 200 self.sy = 150 self.endx = 600 self.endy = 450 # self.avgx = 0 # self.avgy = 0 self.holeflag = 0 self.lflag = 0 self.rflag = 0
def __memory_allocation(self): if not ueye.is_AllocImageMem(self.cam, self.width, self.height, self.bits_per_pixel, self.image_memory, self.memory_id) == ueye.IS_SUCCESS: raise RuntimeError("Memory not allocated") if not ueye.is_SetImageMem(self.cam, self.image_memory, self.memory_id) == ueye.IS_SUCCESS: raise RuntimeError("Memory not set") print("Memory allocated")
def saveImage(self): # try: time1 = datetime.datetime.now() ueye.is_AllocImageMem(self.hcam, self.sensorinfo.nMaxWidth, self.sensorinfo.nMaxHeight, 24, self.pccmem, self.memID) ueye.is_SetImageMem(self.hcam, self.pccmem, self.memID) ueye.is_SetDisplayPos(self.hcam, 100, 100) self.nret = ueye.is_FreezeVideo(self.hcam, ueye.IS_WAIT) self.rawImageTimeStamp = datetime.datetime.now() self.imageTimeStamp = datetime.datetime.now().strftime( '%Y_%m_%d_%H_%M_%S') self.imageName = 'imagem_%s.jpg' % self.imageTimeStamp self.imagePath = self.operationConfigs[ 'savingDirectory'] + self.imageName # self.imagePath = self.operationConfigs['savingDirectory'] + "tmp.jpg" self.FileParams = ueye.IMAGE_FILE_PARAMS() self.FileParams.pwchFileName = self.imagePath self.FileParams.nFileType = ueye.IS_IMG_BMP self.FileParams.ppcImageMem = None self.FileParams.pnImageID = None self.nret = ueye.is_ImageFile(self.hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, self.FileParams, ueye.sizeof(self.FileParams)) ueye.is_FreeImageMem(self.hcam, self.pccmem, self.memID) sleep(.01) ueye.is_ExitCamera(self.hcam) # self.image = np.ones((self.sensorinfo.nMaxHeight.value, self.sensorinfo.nMaxWidth.value), dtype=np.uint8) # ueye.is_CopyImageMem(self.hcam, self.pccmem, self.memID, self.image.ctypes.data) self.image = np.uint8(ndimage.imread(self.imagePath, flatten=True)) time2 = datetime.datetime.now() elapsed_time = time2 - time1 logging.info('Saved: {}! Elasped time (s): {}'.format( self.imageName, elapsed_time.total_seconds()))
def init_acquisition(self): """ Allocate the computer memory according to the size of the image and start the acquisition. """ # Allocate memory for the acquisition # ----------------------------------- self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height Allocate_memory = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if Allocate_memory != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") return else: # Makes the specified image memory the active memory Allocate_memory = ueye.is_SetImageMem(self.hcam, self.pcImageMemory, self.MemID) if Allocate_memory != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") return else: # Set the desired color mode Color_mode = ueye.is_SetColorMode(self.hcam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) # ------------------------------------------------------ Launch_capture = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) if Launch_capture != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") return # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hcam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") return # Launch the live acquisition # --------------------------- self.acquire()
def update_image_memory(self): # 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(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode)
def saveImage(self): try: time1 = datetime.datetime.now() ueye.is_AllocImageMem(self.hcam, self.sensorinfo.nMaxWidth, self.sensorinfo.nMaxHeight, 24, self.pccmem, self.memID) ueye.is_SetImageMem(self.hcam, self.pccmem, self.memID) ueye.is_SetDisplayPos(self.hcam, 100, 100) self.nret = ueye.is_FreezeVideo(self.hcam, ueye.IS_WAIT) self.imageTimeStamp = datetime.datetime.now().strftime( '%Y_%m_%d_%H_%M_%S') self.imageName = 'imagem_%s.jpg' % self.imageTimeStamp self.imagePath = self.savingDirectory + self.imageName self.FileParams = ueye.IMAGE_FILE_PARAMS() self.FileParams.pwchFileName = self.imagePath self.FileParams.nFileType = ueye.IS_IMG_BMP self.FileParams.ppcImageMem = None self.FileParams.pnImageID = None self.nret = ueye.is_ImageFile(self.hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, self.FileParams, ueye.sizeof(self.FileParams)) # print(nret) ueye.is_FreeImageMem(self.hcam, self.pccmem, self.memID) sleep(.1) ueye.is_ExitCamera(self.hcam) time2 = datetime.datetime.now() elapsed_time = time2 - time1 # print('Elasped time (s): {}'.format(elapsed_time)) print('Image saved at {}! Elasped time (ms) {}'.format( self.imageTimeStamp, elapsed_time.microseconds / 1000)) except: print('Image not saved at {}!\n'.format(self.imageTimeStamp)) pass
def Camera_Initialization(self): self.hcam = ueye.HIDS(0) self.ret = ueye.is_InitCamera(self.hcam, None) self.ret = ueye.is_SetColorMode(self.hcam, ueye.IS_CM_MONO12) self.IDS_FPS = float(50) self.newrate = ueye.DOUBLE(self.IDS_FPS) self.rate = ueye.DOUBLE(self.IDS_FPS) self.IDS_exposure = float(20) self.width = 2056 self.height = 1542 self.rect_aoi = ueye.IS_RECT() self.rect_aoi.s32X = ueye.int(0) self.rect_aoi.s32Y = ueye.int(0) self.rect_aoi.s32Width = ueye.int(self.width) self.rect_aoi.s32Height = ueye.int(self.height) ueye.is_AOI(self.hcam, ueye.IS_AOI_IMAGE_SET_AOI, self.rect_aoi, ueye.sizeof(self.rect_aoi)) self.mem_ptr = ueye.c_mem_p() self.mem_id = ueye.int() self.bitspixel = 16 self.ret = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.bitspixel, self.mem_ptr, self.mem_id) self.ret = ueye.is_SetImageMem(self.hcam, self.mem_ptr, self.mem_id) self.ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) #self.lineinc = self.width * int((self.bitspixel + 7) / 8) self.lineinc = self.width * int(self.bitspixel / 8) self.nRet = ueye.is_SetFrameRate(self.hcam, self.rate, self.newrate) self.expms = ueye.DOUBLE(self.IDS_exposure) self.nRet = ueye.is_Exposure(self.hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.expms, ueye.sizeof(self.expms)) self.pixelclock = ueye.c_uint(197) self.nRet = ueye.is_PixelClock(self.hcam, ueye.IS_PIXELCLOCK_CMD_SET, self.pixelclock, 4) #pixelclock = ueye.c_uint() #ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, pixelclock, 4) self.nRet = ueye.is_SetHardwareGain(self.hcam, 100, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER) #gg = ueye.c_uint() #ueye.is_SetHWGainFactor(hcam, ueye.IS_GET_MASTER_GAIN_FACTOR, gg) self.nRet = ueye.is_SetHardwareGamma(self.hcam, ueye.IS_SET_HW_GAMMA_ON)
def setmemory(self): self.ret = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if self.ret != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory self.ret = ueye.is_SetImageMem(self.hcam, self.pcImageMemory, self.MemID) if self.ret != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode self.ret = ueye.is_SetColorMode(self.hcam, self.m_nColorMode)
def _allocate_memory(self): # Allocates memory on the PC and camera # Set the right color mode if int.from_bytes(self._sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(self._cam, self._nBitsPerPixel, self._m_nColorMode) self._bytes_per_pixel = self._nBitsPerPixel / 8 elif int.from_bytes(self._sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self._m_nColorMode = ueye.IS_CM_BGRA8_PACKED self._nBitsPerPixel = ueye.INT(32) self._bytes_per_pixel = self._nBitsPerPixel / 8 elif int.from_bytes(self._sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self._m_nColorMode = ueye.IS_CM_MONO8 self._nBitsPerPixel = ueye.INT(8) self._bytes_per_pixel = self._nBitsPerPixel / 8 else: # for monochrome camera models use Y8 mode self._m_nColorMode = ueye.IS_CM_MONO8 self._nBitsPerPixel = ueye.INT(8) self._bytes_per_pixel = self._nBitsPerPixel / 8 # allocate memory for an image err = ueye.is_AllocImageMem( self._cam, self._width, self._height, self._nBitsPerPixel, self._ppc_img_mem, self._mem_id, ) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err) # make the image memory 'active' err = ueye.is_SetImageMem(self._cam, self._ppc_img_mem, self._mem_id) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err)
def run(self): a = ueye.is_InitCamera(self.hCam, None) b = ueye.is_GetCameraInfo(self.hCam, self.cInfo) c = ueye.is_GetSensorInfo(self.hCam, self.sInfo) d = ueye.is_ResetToDefault(self.hCam) e = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) g = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height h = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) i = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) f = ueye.is_SetColorMode(self.hCam, ueye.IS_CM_MONO12) ueye.is_CaptureVideo(self.hCam, ueye.IS_WAIT) j = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) self.IMAGE_FILE_PARAMS = ueye.IMAGE_FILE_PARAMS( self.pcImageMemory, self.MemID) self.IMAGE_FILE_PARAMS.nFileType = ueye.IS_IMG_PNG self.k = ueye.sizeof(self.IMAGE_FILE_PARAMS) # ueye.is_AutoParameter(self.hCam, ueye.IS_AES_CMD_SET_ENABLE, self.autoParameter, ueye.sizeof(self.autoParameter)) while self.flag: self.data = np.ctypeslib.as_array( ctypes.cast(self.pcImageMemory, ctypes.POINTER(ctypes.c_ubyte)), (self.height * self.pitch, )) self.data.dtype = 'uint16' self.CameraSignal.emit(self.data) time.sleep(0.1) ueye.is_FreeImageMem(self.hCam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.hCam)
def allocate_memory(self): """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_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) if nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") nRet = ueye.is_AllocImageMem(self.hCam, self.rectAOI.s32Width, self.rectAOI.s32Height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode)
def initialize_memory(self): ''' Allocates image memory. Sets: self.mem_id self.mem_image ''' mem_id = ueye.int() mem_image = ueye.c_mem_p() nRet = ueye.is_AllocImageMem(self.input, self.width, self.height, self.bits_per_pixel, mem_image, mem_id) if nRet != ueye.IS_SUCCESS: log.error("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.input, mem_image, mem_id) if nRet != ueye.IS_SUCCESS: log.error("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.input, self.m_nColorMode) self.mem_id = mem_id self.mem_image = mem_image
def _allocate_memory(self): """ Allocates memory on the PC and camera """ # init c-values self._c_width = pue.INT(self._width) self._c_height = pue.INT(self._height) self._c_pixel_bits = pue.INT(self._color_mode.bits_per_pixel) self._bytes_per_pixel = self._color_mode.bits_per_pixel / 8 # the starting memory address for the image, will be returned self._ppc_img_mem = pue.c_mem_p() # the ID for the allocated image, will be returned self._mem_id = pue.INT() # allocate memory for an image err = pue.is_AllocImageMem( self._cam, self._c_width, self._c_height, self._c_pixel_bits, self._ppc_img_mem, self._mem_id, ) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err) # make the image memory 'active' err = pue.is_SetImageMem(self._cam, self._ppc_img_mem, self._mem_id) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err) # create an array in python to which to copy the image self.image_data = np.zeros( (self._height, self._width, self._color_mode.channels), dtype=self._color_mode.dtype, )
# 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() #--------------------------------------------------------------------------------------------------------------------------------------- # 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) 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) # 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:
def __init__(self, deviceID): self.deviceID = deviceID DeviceID = self.deviceID | ueye.IS_USE_DEVICE_ID self.hCam = ueye.HIDS(DeviceID) self.sensorInfo = ueye.SENSORINFO() self.camInfo = ueye.CAMINFO() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() rectAOI = ueye.IS_RECT() self.pitch = ueye.INT() self.nBitsPerPixel = 10 #24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 1 #3: channels for color mode(RGB); take 1 channel for monochrome m_nColorMode = ueye.IS_CM_MONO10 # Y8/RGB16/RGB24/REG32 bytes_per_pixel = int(self.nBitsPerPixel / 8) #nColorMode = IS_CM_MONO10; #self.nBitsPerPixel = 10; # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(self.hCam, None) if nRet != ueye.IS_SUCCESS: print("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that self.camInfo points to nRet = ueye.is_GetCameraInfo(self.hCam, self.camInfo) 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(self.hCam, self.sensorInfo) if nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(self.hCam) if nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) if int.from_bytes(self.sensorInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO10 self.nBitsPerPixel = ueye.INT(10) self.bytes_per_pixel = int(self.nBitsPerPixel / 7) + 1 print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) + 1 print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") self.width = rectAOI.s32Width self.height = rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", self.sensorInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", self.camInfo.SerNo.decode('utf-8')) print("Maximum image self.width:\t", self.width) print("Maximum image self.height:\t", self.height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by self.width # and self.height and its color depth defined by self.nBitsPerPixel nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, m_nColorMode)
def configure_device(self): """ Configure camera. """ self.nRet = ueye.is_ResetToDefault(self.hid) if self.nRet != ueye.IS_SUCCESS: print('Reset ERROR') ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN, self.minExp, 8) ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX, self.maxExp, 8) self.nRet = ueye.is_SetDisplayMode(self.hid, ueye.IS_SET_DM_DIB) if self.nRet != ueye.IS_SUCCESS: print('Display Mode ERROR') ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.minExp, 8 ) ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, self.Exp, 8 ) # Set the right color mode if int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(self.hid, self.bitspixel, self.colorm) self.bytesppixel = int(self.bitspixel / 8) elif int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.colorm = ueye.IS_CM_BGRA8_PACKED self.bitspixel = ueye.INT(32) self.bytesppixel = int(self.bitspixel / 8) elif int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.colorm = ueye.IS_CM_MONO8 self.bitspixel = ueye.INT(8) self.bytesppixel = int(self.bitspixel / 8) else: # for monochrome camera models use Y8 mode self.colorm = ueye.IS_CM_MONO8 self.bitspixel = ueye.INT(8) self.bytesppixel = int(self.bitspixel / 8) self.nRet = ueye.is_AOI(self.hid, ueye.IS_AOI_IMAGE_GET_AOI, self.rect, ueye.sizeof(self.rect)) self.width = self.rect.s32Width self.height = self.rect.s32Height self.pixelSizeMicron = self.sinfo.wPixelSize.value / 100 if self.nRet != ueye.IS_SUCCESS: print('AOI ERROR') self.nRet = ueye.is_AllocImageMem(self.hid, self.width, self.height, self.bitspixel, self.ppcImgMem, self.MemID) if self.nRet != ueye.IS_SUCCESS: print('AllocImageMem ERROR') else: self.nRet = ueye.is_SetImageMem(self.hid, self.ppcImgMem, self.MemID) if self.nRet != ueye.IS_SUCCESS: print('SetImageMem ERROR') else: self.nRet = ueye.is_SetColorMode(self.hid, self.colorm) self.nRet = ueye.is_CaptureVideo(self.hid, ueye.IS_DONT_WAIT) #if self.nRet != ueye.IS_SUCCESS: #print('CaptureVideo ERROR') self.nRet = ueye.is_InquireImageMem(self.hid, self.ppcImgMem, self.MemID, self.width, self.height, self.bitspixel, self.pitch) if self.nRet != ueye.IS_SUCCESS: print('InquireImageMem ERROR')
ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) #Set camera resolution width = 1280 height = 720 #Allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() #For colormode = IS_CM_BGR8_PACKED bitspixel = ueye.INT(24) ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) #Set active memory region ueye.is_SetImageMem(hcam, mem_ptr, mem_id) #Continuous capture to memory ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) #Get data from camera lineinc = width * int((bitspixel + 7) / 8) #Calibrate camera tmp = calib() while(count < 5): cv2.waitKey(100) count+=1 display() cv2.waitKey(0)