genicam / harvesters

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

zero-sized buffers and _gentl.NotAvailableException returned during acquisition #268

Closed aqc-carlodri closed 2 years ago

aqc-carlodri commented 2 years ago

Describe the Bug First of all thank you for the great package! By running the simple script here below:

from harvesters.core import Harvester

h = Harvester()
h.add_file(
    "C:\\Program Files\\MATRIX VISION\\mvIMPACT Acquire\\bin\\x64\\mvGenTLProducer.cti"
)
h.update()

ia = h.create_image_acquirer(0)
nmap = ia.remote_device.node_map
nmap.PixelFormat.value = "RGB8"
nmap.AcquisitionLineRate.value = 5000
nmap.Width.value = 4096
nmap.Height.value = 4096

ia.start_acquisition()

for num_frame in range(20):
    with ia.fetch_buffer() as buffer:
        print(buffer)

ia.stop_acquisition()

ia.destroy()

h.reset()

what I get is a random occurrence of zero-sized buffers and the below exception (not always happening together).

4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 1 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
0 x 0, RGB8, 0 elements,
[]
0 x 0, RGB8, 0 elements,
[]
0 x 0, RGB8, 0 elements,
[]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
0 x 0, RGB8, 0 elements,
[]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 1]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 1 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 0 0]
4096 x 4096, RGB8, 50331648 elements,
[0 0 0 ... 0 1 0]
Traceback (most recent call last):
  File "issue.py", line 20, in <module>
    with ia.fetch_buffer() as buffer:
  File "C:\Users\xxxxx\Miniconda3\envs\genicam\lib\site-packages\harvesters\core.py", line 2778, in fetch_buffer
    if event_manager.buffer.is_complete():
  File "C:\Users\xxxxx\Miniconda3\envs\genicam\lib\site-packages\genicam\gentl.py", line 4562, in is_complete
    return _gentl.Buffer_is_complete(self)
_gentl.NotAvailableException: GenTL exception: Resource or information is not available. (Message from the source: Information 'BUFFER_INFO_IS_INCOMPLETE' is currently not available for this buffer) (ID: -1014)

When the zero-sized buffers occur, often the script hangs and never terminates.

Expected Behavior No zero-content frames (or an exception if that happens). Or should I handle this case internally in my code?

Configuration

Reproducibility I haven't tried with other Harvesters versions. The appearance of the zero-sized buffers and of the exception are quite random and not always reproducible.

Actions You Have Taken I have also tried to use nmap.TestPattern.value = "GreyHorizontalRamp" and the issue occurs identically.

Additional context I'm using a network adapter with 9K jumbo frames and all the recommended NIC settings from the DALSA network configuration guide.

aqc-carlodri commented 2 years ago

An update on this issue. I have tested the acquisition with the Sapera CamExpert from DALSA (obviously with their proprietary capture interface enabled on the NIC) and it works fine without any issues (no incomplete frames or errors). I have checked that this is related to the availability in their software of the "prorpietary" genicam nodes called ""GigE Vision Host Controls", and in particular of the "Image Timeout" node that controls the timeout for a complete image transfer.

I have the feeling that the fact that these nodes are not accessible through the genicam+harvesters package is related to the GenTL producer (MATRIX VISION) that does not support them.

Can someone confirm that this is indeed true?

If yes, I guess it means that I have to move away from the harvesters package (sadly because I really liked it's API!). Or is there a way to "inject" the additional nodes using their XML definition (I might have found it in the SaperaLT SDK package)?

kazunarikudo commented 2 years ago

@aqc-carlodri Hi, if those nodes belong to a GenTL entity, then you should find their names in the output from the following code snippet:

        ia = self.harvester.create_image_acquirer(0)  # type: ImageAcquirer
        for entity in [ia.data_streams[0], ia.remote_device, ia.device,
                    ia.interface, ia.system]:
            print(dir(entity.node_map))

Node injection can be technically possible but if that's the way they do, there's no chance where you can work on those nodes through any third-party API. Good luck. Regards, Kazunari.

kazunarikudo commented 2 years ago

Excuse me, I need to correct the comment above: If those nodes belong to "DALSA's GenTL entity" then any other third-party APIs can do for you. However, if you are fine to just discard the buffer that you gives the NotAvailableException exception I can revise Harvester. Please feel free to tell me your expectation.

aqc-carlodri commented 2 years ago

Thank you for your kind feedback @kazunarikudo! By using your code snippet above I cannot see the the "GigE Vision Host Controls" nodes. I think the problem is that the standard MATRIX VISION GenTL producer is likely not aware of those nodes since they are DALSA-specific. Sadly, DALSA does not distribute a GenTL producer (the *.cti file) for their Linea cameras, so I'm forced to use other generic producers. I will probably try the Common Vision Blox producer that seems to have some support for DALSA-specific features (like TurboDrive).

StefanD986 commented 2 years ago

Hi @kazunarikudo I am facing the same issue as @aqc-carlodri (different camera (Xenics Bobcat), same GenTL producer (Matrix Vision). Can you explain the details on the node injection that you mentioned above?

Node injection can be technically possible

How would I go about that?

StefanD986 commented 2 years ago

Hi @aqc-carlodri try the new 1.3.4 release, it fixed this issue for me, I guess this will also fix it for you.

aqc-carlodri commented 2 years ago

Thanks for the heads up @StefanD986! At the moment I'm using the Common Vision Blox GenTL producer, and it seems that the issue does not occur any more. But I'm not sure it is the producer's fault, since actually I've seen the issue sometimes also with the CVB producer. For the moment I will close this issue, but will re-open in case I face it again.

Although I have to say I'm a little worried by the fact that I could not understand what was going on...