Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def __init__(self, cam):
     super(Capture_Thread, self).__init__()
     self.cam = cam
     self.timeout = 1000
     self.isRunning = True
     self.joined = False
     self.file_param = ueye.IMAGE_FILE_PARAMS()
     self.x = datetime.datetime.now()
     self.FPS = 0
     self.file = open("/home/pi/swim4all/Tirocinio/Tirocinio/fps.txt", "w")
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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()))
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
ueye.is_SetExternalTrigger(hcam, ueye.IS_SET_TRIGGER_SOFTWARE)
wertSet = ueye.c_double(1)
nret = ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, wertSet,
                        ueye.sizeof(wertSet))
print(wertSet)

help(ueye.is_Exposure)

wert = ueye.c_double()
sizeo = ueye.sizeof(wert)
nret = ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, wert, sizeo)
print(wert)
nret = ueye.is_FreezeVideo(hcam, ueye.IS_WAIT)
print(nret)
FileParams = ueye.IMAGE_FILE_PARAMS()
FileParams.pwchFileName = "c:\python-test-image.png"
FileParams.nFileType = ueye.IS_IMG_PNG
FileParams.ppcImageMem = None
FileParams.pnImageID = None
nret = ueye.is_ImageFile(hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, FileParams,
                         ueye.sizeof(FileParams))
print(nret)

nret = ueye.is_FreezeVideo(hcam, ueye.IS_WAIT)
print(nret)
FileParams = ueye.IMAGE_FILE_PARAMS()
FileParams.pwchFileName = "c:\python-test-image1.png"
FileParams.nFileType = ueye.IS_IMG_PNG
FileParams.ppcImageMem = None
FileParams.pnImageID = None
def UEye420_Snapper(Exposure, Gain, File_Location, pixel_clock):
    from pyueye import ueye
    import ctypes
    import time

    saved = False
    while saved == False:
        #CCD Settings and Start-Up
        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)

        PIXELCLOCK_CMD_SET = 6
        PIXELCLOCK_CMD_GET = 4

        pixel = ctypes.c_uint(pixel_clock)
        ueye.is_PixelClock(hcam, PIXELCLOCK_CMD_SET, pixel,
                           ctypes.sizeof(pixel))
        print('PX=', pixel)

        exposure_time = ctypes.c_double(
            Exposure)  #Exposure time in miliseconds
        value = ctypes.c_int(Gain)
        ueye.is_SetHWGainFactor(hcam, ueye.IS_SET_MASTER_GAIN_FACTOR, value)
        ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE,
                         exposure_time, ctypes.sizeof(ctypes.c_double))

        print('Exposure (ms) =', exposure_time)
        print('Gain = ', Gain)
        time.sleep(float(Exposure * 1e-4) * 1.0 +
                   0.2)  #Some time for CCD to set new exposure time
        #initially set to float(Exposure*1e-4)*1.0+1.0 and it works then
        nret = ueye.is_FreezeVideo(hcam, ueye.IS_WAIT)  #Freeze/Snap

        #Save Parameters
        FileParams = ueye.IMAGE_FILE_PARAMS()
        FileParams.pwchFileName = (File_Location)
        FileParams.nFileType = ueye.IS_IMG_BMP
        FileParams.ppcImageMem = None
        FileParams.pnImageID = None

        #IF nret is '1' Image is not saved if nret is "0" Image is saved
        nret = ueye.is_ImageFile(hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, FileParams,
                                 ueye.sizeof(FileParams))
        if nret == 0:
            saved = True
            print('Image Saved!')
        if nret == 1:
            print('Error Image is not Saved!')

        #Shutting the CCD-Down.
        ueye.is_FreeImageMem(hcam, pccmem, memID)
        ueye.is_ExitCamera(hcam)
Exemplo n.º 9
0
g = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI))
width = rectAOI.s32Width
height = rectAOI.s32Height

h = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID)
i = ueye.is_SetImageMem(hCam, pcImageMemory, MemID)
f = ueye.is_SetColorMode(hCam, ueye.IS_CM_MONO12)

ueye.is_CaptureVideo(hCam, ueye.IS_WAIT)

j = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch)




IMAGE_FILE_PARAMS = ueye.IMAGE_FILE_PARAMS(pcImageMemory, MemID)
IMAGE_FILE_PARAMS.nFileType = ueye.IS_IMG_PNG
k = ueye.sizeof(IMAGE_FILE_PARAMS)

nEnable = ctypes.c_int(ueye.IS_AUTOPARAMETER_ENABLE)
state = ctypes.c_int()

m = ueye.is_AutoParameter(hCam, ueye.IS_AES_CMD_SET_ENABLE, nEnable, ueye.sizeof(nEnable))
n = ueye.is_AutoParameter(hCam, ueye.IS_AES_CMD_GET_ENABLE, state, ueye.sizeof(state))

while True:

    data = numpy.ctypeslib.as_array(ctypes.cast(pcImageMemory, ctypes.POINTER(ctypes.c_ubyte)), (height * pitch, ))

    data.dtype = 'uint16'
    # data1 = data.astype('uint8')