I have come across a python wrapper for the EDSDK library. It exposed an API with multiple different functions that can easily be called from my own code. The provided example file works without an issue taking a picture and saving it as a file in my project folder.
To speed this process up instead of saving and loading an image from disk, i want to save the image into a python compatible data structure. There are functions that supposedly load an image from the camera into a buffer on my system, and i can go from there.
Sadly all my attempts have ended in my camera or code crashing.
Here is a section of my code:
edsdk.InitializeSDK()
cam_list = edsdk.GetCameraList()
cam = edsdk.GetChildAtIndex(cam_list, 0) # select first cam
edsdk.OpenSession(cam)
# set callback property on cam
edsdk.SetObjectEventHandler(cam, ObjectEvent.All, callback_object)
# save to host
edsdk.SetPropertyData(cam, PropID.SaveTo, 0, SaveTo.Host)
edsdk.SendCommand(cam, CameraCommand.TakePicture, 0)
# wait for process to finish
time.sleep(4)
if os.name == "nt":
pythoncom.PumpWaitingMessages()
edsdk.TerminateSDK()
With the callback object
def callback_object(event: ObjectEvent, object_handle: EdsObject) -> int:
dir_item_info = edsdk.GetDirectoryItemInfo(object_handle)
# create new Stream
out = edsdk.CreateMemoryStream(dir_item_info["size"])
# download to stream
edsdk.Download(object_handle, dir_item_info["size"], out)
edsdk.DownloadComplete(object_handle)
Accessing this stream from outside the callback object, or defining a new stream led to either the EDSDK crashing or my camera not responding.
Is there a way to get this idea to work, or will i just have to settle on loading from disk?