genicam / harvesters

Image Acquisition Library for GenICam-based Machine Vision System
Apache License 2.0
500 stars 86 forks source link

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

Open G-S-A opened 9 months ago

G-S-A commented 9 months ago

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, 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:

image

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_file("c:/Program Files/JAI/SDK/bin/JaiGevTL.cti")
 h.update()
 h.device_info_list[0]

 # create image acquirer
 ia = h.create(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()
 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()`

If i print device_info_list:

[{'access_status': 2, 'display_name': 'AD-132GE_#0', 'id_': 'MAC->00-0C-DF-08-40-14::JAI Ltd., Japan::AD-132GE_#0', 'model': 'AD-132GE_#0', 'parent': <genicam.gentl.Interface; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::TLInterface > *' at 0x0000022E26E1E450> >, 'serial_number': 'QV132321', 'thisown': True, 'tl_type': 'GEV', 'user_defined_name': '', 'vendor': 'JAI Ltd., Japan', 'version': None}, {'access_status': 2, 'display_name': 'AD-132GE_#0', 'id_': 'MAC->00-0C-DF-08-40-14::JAI Ltd., Japan::AD-132GE_#0', 'model': 'AD-132GE_#0', 'parent': <genicam.gentl.Interface; proxy of <Swig Object of type 'std::shared_ptr< GenTLCpp::TLInterface > *' at 0x0000022E26E1E870> >, 'serial_number': 'QV132321', 'thisown': True, 'tl_type': 'GEV', 'user_defined_name': '', 'vendor': 'JAI Ltd., Japan', 'version': None}]

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/t2.py" 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

Traceback (most recent call last): File "c:/Users/bchns/OneDrive/Escritorio/TRABAJOS Y TAREAS/9 SEMESTRE/TALLER DE INVESTIGACIÓN/AUTOMATIZACION/t2.py", line 15, in ia = h.create(0) File "C:\Users\bchns\AppData\Local\Programs\Python\Python37\lib\site-packages\harvesters\core.py", line 3082, in create return self._create_acquirer(device_proxy=device_proxy, config=config) 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 have: genicam 1.3.0 harvesters 1.4.2 Python 3.7.0

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

DanielRolC commented 4 months ago

I have the same problem with a FLIR thermal camera Did you solve the problem?

polanco06 commented 3 months ago

I have the same problem with a Teledyne thermal camera Has anyone solved it or saved how to solve it?

DanielRolC commented 2 months ago

I have the same problem with a Teledyne thermal camera Has anyone solved it or saved how to solve it?

I've solved it, but the scritp that aquire the image is running locally.

  1. You have to install the Python SDK for your system and the program from the url: https://www.flir.eu/products/spinnaker-sdk/?vertical=machine+vision&segment=iis
  2. You need to login with an email.
  3. Download the programs compatible with your operating system version (you must download the python library and the program).
  4. Follow the instructions in the README.md to install.
  5. Use the "simple_pyspin" library, it is a library that uses PySpin in the background but much easier to use, I recommend you to download the github repository and make tests directly from the scripts the developer has