0

I am using an IDS camera as a necessity at work. I suppose to prepare a desktop application to capture images while the live stream is happening. somehow i could able to stream the live but i cannot caoture images. This image capturing should happen when we I apply triger and non-trigger modes acording to the work related. Is there anybody who has this kind of experience before. I am trying this from pretty long time. please help me.

class ThreadOpenCV(QThread):    
    changePixmap = pyqtSignal(QImage)
    def __init__(self):
        super().__init__()
        #self.source = source
        self.killed = False
        self.grayscale = False
        self.blur = False

        self.running = True    
        self.hcam = ueye.HIDS(0)
        self.ret = ueye.is_InitCamera(self.hcam, None)
        print(f"initCamera returns {self.ret}")
        

        # set color mode
        self.ret = ueye.is_SetColorMode(self.hcam, ueye.IS_CM_BGR8_PACKED)
        print(f"SetColorMode IS_CM_BGR8_PACKED returns {self.ret}")
        #self.ret = ueye.is_SetExternalTrigger(self.hcam,ueye.IS_SET_TRIGGER_HI_LO_SYNC)

        # set region of interest
        self.width = 1280
        self.height = 1080
        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))
        print(f"AOI IS_AOI_IMAGE_SET_AOI returns {self.ret}")

        # allocate memory
        self.mem_ptr = ueye.c_mem_p()
        self.mem_id = ueye.int()
        self.bitspixel = 24 # for colormode = IS_CM_BGR8_PACKED
        ######
        self.ret = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.bitspixel,
                                    self.mem_ptr, self.mem_id)
        print(f"AllocImageMem returns {self.ret}")
        
        # set active memory region
        self.ret = ueye.is_SetImageMem(self.hcam, self.mem_ptr, self.mem_id)
        print(f"SetImageMem returns {self.ret}")

        # continuous capture to memory
        self.ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT)
        print(f"CaptureVideo returns {self.ret}")
        
        # get data from camera and display
        self.lineinc = self.width * int((self.bitspixel + 7) / 8)
    def run(self):
        
        print('start')
        try:
            print('start1')
            while self.running:
                print('start2')
            #ret, frame = cap.read() 
                frame = ueye.get_data(self.mem_ptr, self.width, self.height, self.bitspixel, self.lineinc, copy=True)
                print('start3')
                frame = np.reshape(frame, (self.height, self.width, 3))
                print('start4')
                #print(frame)
                #if ret:
                self.h, self.w, self.ch = frame.shape
                bytes_per_line = self.ch * self.w   # PEP8: `lower_case_names` for variables                
                image = QImage(frame.data, self.w, self.h, bytes_per_line, QImage.Format_RGB888)
                print('start5')
                self.image = image.scaled(1280, 1080, Qt.KeepAspectRatio)
                self.changePixmap.emit(self.image)
            #cap.release()
            #print('stop')
        except Exception as e:
            print('Exception: {}'.format(e))
            print('error{}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__,)

    def kill(self):
        self.running = False
Sree
  • 11
  • 1

0 Answers0