genicam / harvesters

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

ia.fetch() only returns one image for U3V camera #360

Open adt47 opened 2 years ago

adt47 commented 2 years ago

Describe the Issue I am trying to stream a U3V machine vision camera from SVS-Vistek. The call to ia.fetch() is contained in a loop which returns a single image. The second time through the loop ia.fetch() never returns and ends up timing out. At least this is what happens when using the transport layer file mvGenTLProducer.cti provided by MatrixVision. If I use the file sv_u3v_tl_x64.cti provided by SVS-Vistek, the first call to ia.fetch() fails due to "Invalid layout of buffer attached to chunk parser" exception.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Sample Code I can show a piece of code that demonstrates the reported phenomenon:

If yes, please provide a sample code:

h = Harvester()
        # h.add_file('C:/Program Files/MATRIX VISION/mvIMPACT Acquire/bin/x64/mvGenTLProducer.cti')
        h.add_file('C:/Program Files/SVS-VISTEK GmbH/SVCam Kit/TLUsb/bin/sv_u3v_tl_x64.cti')

        h.update()
        for i in range(len(h.device_info_list)):
            print(h.device_info_list[i])
        ia = h.create({'serial_number': '66860'})

        width = ia.remote_device.node_map.SensorWidth.value
        height = ia.remote_device.node_map.SensorHeight.value
        ia.remote_device.node_map.AcquisitionMode.value = "Continuous"

        try:
            ia.start()
            i = 0
            done = False
            while not done:
                with ia.fetch(timeout=3) as buffer:
                    # I do some stuff with the image
                    fps = ia.statistics.fps
                    print("FPS: ", fps)

                    i = i + 1
                    # buffer.queue()
        except Exception as e:
            traceback.print_exc(file=sys.stdout)
        finally:
            ia.stop()
            ia.destroy()
            print('fin')
            h.reset()

If applicable, please paste the actual output (its whole traceback, etc) here: This is the output using the transport layer from MatrixVision:

False
FPS:  0.0
False
Traceback (most recent call last):
  File "D:/Documents/WA/svf_testbed/harvester.py", line 83, in <module>
    with ia_left.fetch(timeout=3) as buffer:
  File "D:\opt\Anaconda3\envs\svf_testbed\lib\site-packages\harvesters\core.py", line 2386, in fetch
    raw_buffer = self._fetch(
  File "D:\opt\Anaconda3\envs\svf_testbed\lib\site-packages\harvesters\core.py", line 2262, in _fetch
    raise TimeoutException
_gentl.TimeoutException

This is the output using the transport layer from SVS-Vistek:

False
Traceback (most recent call last):
  File "D:/Documents/WA/svf_testbed/harvester.py", line 83, in <module>
    with ia_left.fetch(timeout=3) as buffer:
  File "D:\opt\Anaconda3\envs\svf_testbed\lib\site-packages\harvesters\core.py", line 2389, in fetch
    buffer = self._finalize_fetching_process(raw_buffer, is_raw)
  File "D:\opt\Anaconda3\envs\svf_testbed\lib\site-packages\harvesters\core.py", line 2320, in _finalize_fetching_process
    self._update_chunk_data(buffer=raw_buffer)
  File "D:\opt\Anaconda3\envs\svf_testbed\lib\site-packages\harvesters\core.py", line 2203, in _update_chunk_data
    self._chunk_adapter.attach_buffer(buffer.raw_buffer[:size])
  File "D:\opt\Anaconda3\envs\svf_testbed\lib\site-packages\genicam\genapi.py", line 2963, in attach_buffer
    self._adapter.attach_buffer(self._buffer, statistics)
  File "D:\opt\Anaconda3\envs\svf_testbed\lib\site-packages\genicam\genapi.py", line 3130, in attach_buffer
    return _genapi._ChunkAdapterU3V_attach_buffer(self, pBuffer, pAttachStatistics)
_genapi.RuntimeException: Invalid layout of buffer attached to chunk parser! : RuntimeException thrown (file 'ChunkAdapterU3V.cpp', line 95)
fin

Expected Behavior I expect multiple frames to be grabbed from the camera and displayed using OpenCV (OpenCV display code was removed to keep this short).

Configuration

Reproducibility

This phenomenon can be stably reproduced:

This happens every time I run the code.

Actions You Have Taken

Additional context I can stream the camera using a provided GUI from SVS-Vistek and their transport layer file. There is a script provided by MatrixVision, that has the same behavior as my code using their transport layer file (I get one image then wait forever for the second). When coding in C/C++ with the SVS-Vistek SDK, I have to declare the number of buffers at 4; I don't know if this relevant or how I would do this using harvesters. Also, in the print out you will notice a couple of False prints. I put this statement in the fetch() method on line 2379 of core.py. It prints the result of self.thread_image_acquisition.is_running(), so the acquisition thread is not running.

jcormier commented 1 year ago

Our camera also doesn't support Chunk transfers. And ia.remote.node_map.ChunkModeActive does not exist. Sticking with harvesters 1.3.2 until we can figure this out.

OS: windows 10
Harvester: 1.3.8
Genicam: 1.1.0
Python (Anaconda): 3.8.12
GenTL Producer: Critical Link
GenTL Viewer: 2.7.0
Camera: MityCAM-35MMFHDXS
In [5]: dir(ia.remote_device.node_map)
Out[5]: 
['AcquisitionControl',
 'AcquisitionFrameCount',
 'AcquisitionFramePeriod',
 'AcquisitionFrameRate',
 'AcquisitionMode',
 'AcquisitionStart',
 'AcquisitionStop',
 'AdcBlkClamp',
 'AdcCdsGain',
 'AdcSelection',
 'AdcVgaGain',
 'AmpGain',
 'BadPixelReplacementEnable',
 'BadPixelReplacementMap',
 'DeviceControl',
 'DeviceFirmwareVersion',
 'DeviceManufacturerInfo',
 'DeviceModelName',
 'DeviceReset',
 'DeviceSFNCVersionMajor',
 'DeviceSFNCVersionMinor',
 'DeviceSFNCVersionSubMinor',
 'DeviceSelect',
 'DeviceSerialNumber',
 'DeviceVendorName',
 'DeviceVersion',
 'DigitalIOControl',
 'ExecRead',
 'ExecWrite',
 'ExposureTime',
 'FpgaVersion',
 'FrameCountMax',
 'Fx3Version',
 'Height',
 'HeightMax',
 'ImageFormatControl',
 'LineMode',
 'LineSelector',
 'LineSource',
 'LineStatus',
 'Max10CtrlVersion',
 'Max10Version',
 'MinFramePeriod',
 'OffsetX',
 'OffsetY',
 'PayloadSize',
 'PixelFormat',
 'RegAddress',
 'RegValue',
 'Root',
 'SensorHeight',
 'SensorPeekPoke',
 'SensorWidth',
 'SoftwareBuildDate',
 'TestControl',
 'TestPattern',
 'TestPendingAck',
 'TransportLayerControl',
 'TriggerActivation',
 'TriggerMode',
 'TriggerSelector',
 'UserOutputSelector',
 'UserOutputValue',
 'VSkip',
 'Voltage',
 'VoltageSelect',
 'Width',
 'WidthMax',
...