Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tisfrabber LoadDeviceStateFromFile() and SnapImage #76

Open
pfernand3 opened this issue Mar 29, 2024 · 1 comment
Open

tisfrabber LoadDeviceStateFromFile() and SnapImage #76

pfernand3 opened this issue Mar 29, 2024 · 1 comment

Comments

@pfernand3
Copy link

pfernand3 commented Mar 29, 2024

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
Copy link
Collaborator

TIS-Stefan commented Apr 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants