Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(API) Cam2D_Snapshot returns wrong size image
#1
The attached code consistently writes a 100x75 image instead of the expected 640x480.  In the code I was writing when I discovered the bug, it sometimes returns the correct size and sometimes the wrong size, so it looks like a race condition.  The tiny incorrect size also looks suspiciously similar to the size of the thumbnail I see in the camera preview window.

Relevant code is this:

virtual_camera = RDK.Cam2D_Add(item_object=station, cam_params="FOCAL_LENGTH=1.93 FOV=65.5 SIZE=640x480")

filename = "/tmp/bug.png"
RDK.Cam2D_Snapshot(file_save_img=filename)

I'm on Ubuntu 22.04, RoboDK v5.4.1 (64 bit)

Full code:


Code:
#!/usr/bin/python3

from robolink import *    # API to communicate with RoboDK
from robodk import *      # robodk robotics toolbox

RDK = Robolink()

def clear_station(rdk):
    station_name = "Camera bug"

    # If there was already a station for this script, delete it
    station = rdk.Item(station_name)
    try:
        station.Delete()
    except robolink.InputError as e:
        pass

    station = rdk.AddStation(station_name)
    return station

station = clear_station(RDK)
virtual_camera = RDK.Cam2D_Add(item_object=station, cam_params="FOCAL_LENGTH=1.93 FOV=65.5 SIZE=640x480")

filename = "/tmp/bug.png"
RDK.Cam2D_Snapshot(file_save_img=filename)

While we're on the topic, are all the misspelled "LENGHT"s in the API docs (eg., "FOCAL_LENGHT" instead of "FOCAL_LENGTH") for the camera setup string what we should actually use, or is the library actually expecting the correct spelling?


Attached Files Image(s)
   
#2
Hi,

In order for the snapshot to work, the preview window must be opened --and it takes some time to do so.
Adding a pause(0.1) after Cam2D_Add should fix your issue.

You can use the correct or the misspelled spelling. I'll update the documentation with the correct spelling.
Thank you for pointing that out.
Find useful information about RoboDK and its features by visiting our Online Documentation and by watching tutorials on our YouTube Channel.
#3
Thanks for the quick reply. I added a 3 second time.sleep(3) after Cam2D_Add() and it still consistently produces a tiny image. The snapshot window also stays small. Maybe it's something about gnome not accepting a size hint? But isn't the SNAPSHOT parameter supposed to make the saved image size independent of the preview window? Setting that to 640x480 doesn't help either.
#4
I am not experiencing this on Windows, I'll test this on Ubuntu as soon as I can.

Indeed, SIZE is the camera native sensor size, and SNAPSHOT is the output size when saving on disk on retrieving through socket.

What is the size of the image when you retrieve it directly through the API?

Code:
bytes_img = RDK.Cam2D_Snapshot('', cam_item)
nparr = np.frombuffer(bytes_img, np.uint8)
img = cv.imdecode(nparr, cv.IMREAD_COLOR)
Find useful information about RoboDK and its features by visiting our Online Documentation and by watching tutorials on our YouTube Channel.
#5
Hello,

WINDOWFIXED and SNAPSHOT=640x480 parameters did not resolve the issue.

I noticed the issue was not present when adding a breakpoint on Cam2D_Add. Adding a pause after the clear_station call fixes it. The issue is not present when adding a camera to a station without deleting it first. The code below works for me.

Code:
#!/usr/bin/python3

from robolink import *    # API to communicate with RoboDK
from robodk import *      # robodk robotics toolbox

RDK = Robolink()

def clear_station(rdk):
   station_name = "Camera bug"

   # If there was already a station for this script, delete it
   station = rdk.Item(station_name)
   try:
       station.Delete()
   except robolink.InputError as e:
       pass

   station = rdk.AddStation(station_name)
   return station

station = clear_station(RDK)
pause(0.3)
virtual_camera = RDK.Cam2D_Add(item_object=station, cam_params="FOCAL_LENGTH=1.93 FOV=65.5 SIZE=640x480")

filename = "/tmp/bug.png"
RDK.Cam2D_Snapshot(file_save_img=filename)
Find useful information about RoboDK and its features by visiting our Online Documentation and by watching tutorials on our YouTube Channel.
  




Users browsing this thread:
1 Guest(s)