Error when opening DeviceFactory: RuntimeError C-API call failed, LoadImageFileW

Hello,

I am trying to connect a camera via the CVB Python wrapper.

When I start with the following simple Python code…

import cvb
GenICamDevice = cvb.DeviceFactory.open(cvb.install_path()+"/Drivers/GenICam.vin")

, I very often (and sometimes very persistently) get the following error message:

Traceback (most recent call last):

  File "<ipython-input-3-bcd6810e309b>", line 1, in <module>
    GenICamDevice = cvb.DeviceFactory.open(cvb.install_path()+"/Drivers/GenICam.vin")

RuntimeError: {C-API call failed} ({LoadImageFileW})

The installation was done according to the example in this forum. It has also already worked before, so the camera and / or installation seems principally correct.
Running the CVB Management Console shows, that the camera is working (sending images).

Can anybody help me, solving the problem? Do you need more information?

My system:
Win 10
Python 3.6.5 (run via Spyder)
Common Vision Blox Bindings 1.00.000 (x64)
CommonVisionBlox 13.01.006 (x64).exe
Camera (Dalsa Nano) connected via GigE and PoE injector

Hi Tom,

welcome to our forum.

One obvious question first:
When you run your code, are all other applications that could possibly block the driver closed (eg. ManagementConsole)?

Cheers
Chris

Hi Chris,

Currently (after a complete restart) it’s working (with ManagementConsole closed).
But before I tried it both with and without ManagementConsole.

I figured that after startup of the computer, I can only run my test program after I had made a quick shot with the ManagementConsole before.
And after stopping a Python code, it can be only re-run without above error, after killing the Python interpreter.

Could it be that there are still processes running in the background? If so, can I identify them somehow?

Best wishes and thanks for your help,
Tom

Do you launch your application from autostart?

No, from within Spyder (Python IDE).

Hi @Tom

As the error says the call fails at the C-API level. Therefore it is most likely that it has nothing to do with Python in general.

But as you wrote:

Unfortunately that is quite common as Python and especially Spider is not very transparent about resource management. I suggest using the the “with” statement.

with cvb.DeviceFactory.open(...) as device:
  pass # do something with the device here, the device will be closed after you left the with scope

For a quick check if the device is accessible you can run GenICam Browser to discover devices, a red camera icon indicates that the device is currently inaccessible.

1 Like

Hi Andreas,

Opening with the “with” statement works without errors. So the problem is solved.

Thanks,
Tom

1 Like

I know it is late, but maybe it helps:
the connection needs to be closed properly for Python to reopen it later.

device = cvb.DeviceFactory.open(cvb.install_path() + "/drivers/GenICam.vin")
img_stream = device.stream
img_stream.start()
img_stream.stop()
device.close()

this works fine for me

2 Likes

Thanks for the answer! I’ll try it ASAP (I currently don’t have access to the camera).

1 Like

pip install cython
work for me :wink:

Hello guys,

I am having the same issue that @Tom described, however none of the proposed solutions have fixed my problem. My error message also is less specific.

RuntimeError                              Traceback (most recent call last)
<ipython-input-11-efb389850ddd> in <module>
----> 1 with cvb.DeviceFactory.open(cvb.install_path() + "drivers\GenICam.vin") as device:
      2     pass
RuntimeError: C-API call failed

I am working in JupyterLab instead of Spyder.
The camera I am trying to find is connected by USB and shows up green when I check in the ManagementConsole.
Other cvb functions seem to be working just fine.

Thanks,
Kyra

Can you try with "drivers\\GenICam.vin" instead (double backslash)?

Thanks for the quick reply!

Sadly neither "drivers\\GenICam.vin" nor "\drivers\\GenICam.vin"changes anything.

If anyone has an idea where I should be looking to find the cause of the issue (file paths, module documentation, etc.) that would also be incredible helpful.

I assume this is running on Windows. I would then expect cvb.install_path() to point to something like C:\Program Files\STEMMER IMAGING\Common Vision Blox\ (mind the trailing \\ and the double backslashes). If you can confirm that for your system then I would expect "Drivers\\GenICam.vin" to work (upper/lower case should not be an issue).

Just to be sure: You did configure and save a suitable “GenICam.ini” file with the GenICamBrowser? That is actually needed for this approach to opening. And the GenICamBrowser is closed when you call open?

I am running everything on Windows and print(cvb.install_path()) returns
"C:\Program Files\STEMMER IMAGING\Common Vision Blox\" just like you said.

I didn’t explicitly configured the file by hand, but there is a “GenICam.ini” at the end of the file path "C:\ProgramData\STEMMER IMAGING\Common Vision Blox\Drivers".
The camera I want to use shows up and is green in the GenICamBrowser.

And yes, the GenICamBrowser is closed while I am trying to access the camera.

Hi @kreinert ,

it is not sufficient that the camera is visible on the left hand side in the GCBrowser. What is needed (and what @illusive meant) is the configuration of that device into the right hand section called “Configured Devices”

Try to

  • right click on the device in the “Available Devices” section
  • then select “Add to configured devices” and finally
  • hit the Save button in the Configured Devices section (see yellow marked button in the image)
    image

As a result, the Genicam.ini is filled with the required information to open the driver from software. Retry your python script.

1 Like

Thanks for the advice @illusive and @s-woe, turns out i was missing the actual configuration because I had an issue actually saving the configuration file.
Once that issue was resolved, the configuration could be saved and the
RuntimeError: C-API call failed disappeared.

The program still freezes and doesn’t do what it is supposed to, but that is a problem for another thread.

1 Like

After a lot of trial and error, I wanted to add what I have figured out in the hopes that it might save someone with the same problem a lot of time.

It turns out that my program only works on the first run after the camera is plugged into the computer. I am opening the camera in a with statement.

If I restart the kernel or simple try to run the cell that opens the device again, it throws the RuntimeError: C-API call described above.

Did/Do you by any change abort the execution of the program, i.e. during a successful run?
Or another execption is uncatched?
Or does it exit normally?

Background for this question is, that a camera depending on the camera technology might be in an undefined state, if an appliction uses the camera crashes.
I.e. catch all exceptions.
However this is an assuption, not really sure if this relates to your issue.

At the moment the image processing code takes only a file as input and doesn’t have anything to do with accessing the camera. I do not throw any exceptions in my code.
I am opening the device using a with statement, and I am manually aborting the stream afterwards (see below).
Does stream.abort() not release the camera? What should I be using instead?

with cvb.DeviceFactory.open("C:\Program Files\STEMMER IMAGING\Common Vision Blox\Drivers\GenICam.vin") as device:
    stream = device.stream()
    stream.start()
    
    image, status = stream.wait()
    if status == cvb.WaitStatus.Ok:  
        image.save("acquired_image.jpg")
        # image processing code:
        ri_1 = rip.rectangle_image("acquired_image.jpg")
        ri_1.evaluate_image(high_threshold=200, low_threshold=100)
        
    stream.abort()