Error when trying to connect a JAI AD_132GE#1 camera with Python, using the Harvester library

121 Views Asked by At

I am starting to use IP cameras, and I have to capture an image, specifically from the JAI AD-132GE camera using Python, I am starting by using the Harvester library which apparently would allow me to make this connection, however I have not been able to obtain images.

I have used the tool that JAI provides JAI Camera Control Tool and with it I can perform the image acquisition:

However, when I try to link it in Python I get an error, this is the code:

import cv2
import numpy as np
import matplotlib.pyplot as plt
from harvesters.core import Harvester

# create harvester object
h = Harvester()
h.add_cti_file("c:/Program Files/JAI/SDK/bin/JaiGevTL.cti")
h.update_device_info_list()
h.device_info_list[0]

# create image acquirer
ia = h.create_image_acquirer(0)
width = 2560
height = 1960
ia.device.node_map.Width.value, ia.device.node_map.Height.value = width, height
ia.device.node_map.PixelFormat.value = 'Mono8'

# create videowriter
fourcc = cv2.VideoWriter_fourcc(*'XVID')
fps = 25.0
out = cv2.VideoWriter('output.avi',fourcc, fps, (width,height))

# start image aq
ia.start_image_acquisition()
while(True):
    with ia.fetch_buffer() as buffer:
        # Let's create an alias of the 2D image component:
        component = buffer.payload.components[0]

        #     # Let's see the acquired data in 1D:
        #    _1d = component.data

        # Reshape the NumPy array into a 2D array:
        frame = component.data.reshape(component.height, component.width)
    
        # perform any operation on the image
    
        # convert to bgr for video saving
        frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) 

        # save frames
        out.write(frame)
    
        # save snapshot
        #    cv2.imwrite('snap.jpg', frame)
    
        # show live acquisition
        cv2.imshow('frame',frame)
    
        # exit live aq with "q"-key
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

out.release()
cv2.destroyAllWindows()
ia.stop_image_acquisition()
ia.destroy()
h.reset()`

This is the error it gives me when running the program:

PS C:\Users\bchns\OneDrive\Escritorio\TRABAJOS Y TAREAS\9 SEMESTRE\TALLER DE INVESTIGACIÓN\AUTOMATIZACION> & C:/Users/bchns/AppData/Local/Programs/Python/Python37/python.exe "c:/Users/bchns/OneDrive/Escritorio/TRABAJOS Y TAREAS/9 SEMESTRE/TALLER DE INVESTIGACIÓN/AUTOMATIZACION/test.py" c:/Users/bchns/OneDrive/Escritorio/TRABAJOS Y TAREAS/9 SEMESTRE/TALLER DE INVESTIGACIÓN/AUTOMATIZACION/test.py:8: DeprecationWarning: please consider to use add_file() instead of add_cti_file(). h.add_cti_file("c:/Program Files/JAI/SDK/bin/JaiGevTL.cti") c:/Users/bchns/OneDrive/Escritorio/TRABAJOS Y TAREAS/9 SEMESTRE/TALLER DE INVESTIGACIÓN/AUTOMATIZACION/test.py:9: DeprecationWarning: please consider to use update() instead of update_device_info_list(). h.update_device_info_list() GenTL producer does not implement IFGetParentTL GenTL producer does not implement DevGetParentIF GenTL producer does not implement DSGetParentDev GenTL producer does not implement DSGetNumBufferParts GenTL producer does not implement DSGetBufferPartInfo c:/Users/bchns/OneDrive/Escritorio/TRABAJOS Y TAREAS/9 SEMESTRE/TALLER DE INVESTIGACIÓN/AUTOMATIZACION/test.py:13: DeprecationWarning: please consider to use create() instead of create_image_acquirer(). ia = h.create_image_acquirer(0) Traceback (most recent call last): File "c:/Users/bchns/OneDrive/Escritorio/TRABAJOS Y TAREAS/9 SEMESTRE/TALLER DE INVESTIGACIÓN/AUTOMATIZACION/test.py", line 13, in <module> ia = h.create_image_acquirer(0) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\harvesters\core.py", line 3213, in create_image_acquirer file_dict=file_dict) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\harvesters\core.py", line 3113, in _create_acquirer file_dict=file_dict, parent=self) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\harvesters\core.py", line 1634, in __init__ xml_dir_to_store=self._xml_dir) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\harvesters\core.py", line 489, in __init__ xml_dir_to_store=xml_dir_to_store) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\harvesters\core.py", line 284, in __init__ port else None File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\harvesters\core.py", line 355, in _create_node_map node_map.connect(concrete_port, port.name) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\genicam\genapi.py", line 1950, in connect return self._connect(*args) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\genicam\genapi.py", line 1860, in _connect return _genapi.NodeMap__connect(self, *args) _genapi.AccessException: Feature not present (reference not valid) : AccessException thrown (file 'NodeMapRef.h', line 497)

I would appreciate if anyone has an idea of ​​what the error could be and could educate me on the subject, greetings.

0

There are 0 best solutions below