IC-Imaging-Control-Samples icon indicating copy to clipboard operation
IC-Imaging-Control-Samples copied to clipboard

tisfrabber LoadDeviceStateFromFile() and SnapImage

Open pfernand3 opened this issue 3 months ago • 1 comments

Hello,

I want to take images with several DFK 33GX265 cameras, loading the configurations from a .xml file and I have the following python code in Windows:

    def __init__(self, configurations, properties, triggerproperty, imageprefix, prop_path):
            ic = ctypes.cdll.LoadLibrary(TIS_PATH + "/tisgrabber_x64.dll")
            tis.declareFunctions(ic)
            ic.IC_InitLibrary(0)
            
            prop_file = os.path.join(TIS_PATH, prop_path)
        
            # Cargar cámara con archivo de propiedades (archivo de estado ic Capture 2.5 en xml)    
            self.name = prop_file
            #self.hGrabber = ic.IC_CreateGrabber()
            #ic.IC_OpenDevByUniqueName(self.hGrabber, tis.T(self.config['nombre_dispositivo']))
    
            # Abrir dispositivo
           self.hGrabber =  ic.IC_LoadDeviceStateFromFile(None, tis.T(prop_file))        
    
            if not ic.IC_IsDevValid(self.hGrabber):
                print("Fallo al abrir la cámara en ", prop_file)
            
            
            # Establecer desde cameras.json los valores de exposición y ganancia
            ic.IC_SetPropertySwitch(self.hGrabber, tis.T("Exposure"), tis.T("Auto"), 0)
            ic.IC_SetPropertySwitch(self.hGrabber, tis.T("Gain"), tis.T("Auto"), 0)
            ic.IC_SetPropertyAbsoluteValue(self.hGrabber, tis.T("Exposure"), tis.T("Value"),    
                ctypes.c_float(self.properties['ExposureTime']))
            ic.IC_SetPropertyAbsoluteValue(self.hGrabber, tis.T("Ganancia"), tis.T("Valor"),    
                ctypes.c_float(self.properties['Ganancia']))
           ic.IC_StartLive(self.hGrabber, 1)
    
    def get_image(self):
         
        if not ic.IC_IsDevValid(self.hGrabber):
                    print('Not open device')
                    return None
                    
         img=ic.IC_SnapImage(self.hGrabber, 2000)
          ic.IC_SaveImage(self.hGrabber, tis.T(f"test_{self.imageprefix}.png"),
                                  tis.ImageFileTypes['PNG'],90)
                                  
     for cameraconfig in cameraconfigs['cameras']:
              cameras = list()                 
              cam = CAMERA(cameraconfig, cameraconfig['properties'],cameraconfig['trigger'],cameraconfig['imageprefix'], 
                          cameraconfig["properties_path"])
              cameras.append(cam)
    
     for camera in cameras:
                    camera.get_Image()

The result of the saved image test.png is a black image and the result of SnapImage is 0. how can I solve it? The rest of the code returns what it should without giving error.

I can't find any documentation about the ic.IC_LoadDeviceStateFromFile() function.

Best regards and thanks in advance, Patricia

pfernand3 avatar Mar 29 '24 12:03 pfernand3