TheImagingSource / IC-Imaging-Control-Samples

Windows Sample in C#, C++, Python, LabVIEW and Java
94 stars 52 forks source link

tisfrabber LoadDeviceStateFromFile() and SnapImage #76

Open pfernand3 opened 7 months ago

pfernand3 commented 7 months ago

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

TIS-Stefan commented 7 months ago

Hello Patricia

please make sure, the exposure time and gain values are high enough to get an image. Also make sure, the camera is not in trigger mode. You can check that with IC Capture 2.5, it shows no live video, if the camera is in trigger mode.

Latest IC Capture 2.5 can export a Device State XML from "File" menu. I suggest to setup the camera with IC Capture 2.5, export a Device State XML file and used in your script.

You may also consider use IC Imaging Control 4, which has a more sophisticated Python port: https://www.theimagingsource.com/en-us/documentation/ic4python/index.html

Stefan