Error while creating and capturing with File Camera

General Information

  • Product: C57
  • Serial Number: 232192
  • Ensenso SDK Version: 4.0.1502
  • Operating System: Linux

Problem / Question

Hello,

I am currently trying to create a file camera to process already recorded data. I have created the corresponding enscam files with the camera and stored them in a folder.
Unfortunately, I can’t open them with my script. What could be the problem here?

if __name__ == "__main__":
    NxLib()
    camera_serial = "232192-Color"
    with NxLibCommand(CMD_CREATE_FILE_CAMERA) as cmd:
        cmd.parameters()[ITM_PATH] = "/path_to_data/232192-Color.enscam"
        cmd.parameters()[ITM_SERIAL_NUMBER] = camera_serial
        cmd.execute()
    camera = Camera.from_serial(camera_serial)
    camera.capture()

The error message is

ParametersInvalid : The specified serial number ‘232192-Color’ does not match any open camera.

when trying to capture, although the serial should be correct. Any ideas?

Hi,

the Python Camera class is meant to be used as a context manager and calls the Open and Close commands for you when entering or exiting the context. So you have to do:

with Camera.from_serial(camera_serial) as camera:
    # Camera is open while in this block.
    camera.capture()

Other than that I think your script should work.

1 Like

Hi Daniel,

I would like to write the initialization and use of the camera in an OOP manner. Can there be a work around so that we can capture data without using it in a context manager?

The context managers provided by the Python interface are just for convenience. You can use the underlying JSON API to control the NxLib however you want.

The Camera context manager calls the Open and Close commands. You can replace it with something like the following code:

with NxLibCommand(CMD_OPEN) as cmd:
    cmd.parameters()[ITM_CAMERAS] = camera_serial
    cmd.execute()

# You can still use Camera here, but it does not run Open and Close.
# Alternatively you can also achieve the same functionality with
# manual access to the JSON API.
camera = Camera.from_serial(camera_serial)
camera.capture()

# Close the camera when you don't need it anymore.
with NxLibCommand(CMD_CLOSE) as cmd:
    cmd.parameters()[ITM_CAMERAS] = camera_serial
    cmd.execute()