Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Camera parameters of retrieved camera item
#1
I'm trying to get a snapshot from a camera in a station, by running a Python script in the station tree. It looks like this:
Code:
cam_id = RDK.Item('Camera 1',robolink.ITEM_TYPE_CAMERA)
if not cam_id.Valid():
cam_id = RDK.Cam2D_Add(camFrame, 'FOCAL_LENGTH=6 FOV=32 FAR_LENGTH=5000 SIZE=1080x810')

RDK.Cam2D_Snapshot(RDK.getParam('PATH_OPENSTATION') + '/snapshot.png', cam_id)
If no camera item named 'Camera 1' is present, it works as intended: a camera item named 'Camera 1' is added to the tree, and the 1080x810 snapshot is created.

Now, if I run the Python script a second time, 'Camera 1'  is already present in the station, the camera item is found, and a snapshot is created, but it is tiny: 160x120 pixels. It seems like the set camera parameters are lost.

How should I solve this?

Kind regards,

Maarten
#2
I think I solved it, by repeating the Cam2D_Add command even when the camera already exists, and adding the camera item as a third variable:
Code:
cam_id = RDK.Item('Camera 1',robolink.ITEM_TYPE_CAMERA)
if not cam_id.Valid():
cam_id = RDK.Cam2D_Add(camFrame, 'FOCAL_LENGTH=6 FOV=32 FAR_LENGTH=5000 SIZE=1080x810')
else:
cam_id = RDK.Cam2D_Add(camFrame, 'FOCAL_LENGTH=6 FOV=32 FAR_LENGTH=5000 SIZE=1080x810',cam_id)

RDK.Cam2D_Snapshot(RDK.getParam('PATH_OPENSTATION') + '/snapshot.png', cam_id)
Still, it seems strange to me to have to specify camera parameters more than once.
#3
Hi Maarten,

To reuse a camera that was closed, you need to open the preview window manually.
You do not need to call Cam2D_Add again.


Code:
#----------------------------------
# Get the camera item
cam_item = RDK.Item(CAM_NAME, robolink.ITEM_TYPE_CAMERA)
if not cam_item.Valid():
   cam_item = RDK.Cam2D_Add(RDK.AddFrame(CAM_NAME + ' Frame'), CAM_PARAMS)
   cam_item.setName(CAM_NAME)
cam_item.setParam('Open', 1)
Find useful information about RoboDK and its features by visiting our Online Documentation and by watching tutorials on our YouTube Channel.
#4
Thank you Sam, cam_item.setParam('Open', 1) did the trick!
  




Users browsing this thread:
1 Guest(s)