RoboDK Forum
Camera parameters of retrieved camera item- Printable Version

+- RoboDK Forum (//www.sinclairbody.com/forum)
+-- Forum: RoboDK (EN) (//www.sinclairbody.com/forum/Forum-RoboDK-EN)
+--- Forum: RoboDK API (//www.sinclairbody.com/forum/Forum-RoboDK-API)
+--- Thread: Camera parameters of retrieved camera item (/Thread-Camera-parameters-of-retrieved-camera-item)



Camera parameters of retrieved camera item-Maarten-12-15-2022

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


RE: Camera parameters of retrieved camera item-Maarten-12-15-2022

I think I solved it, by repeating theCam2D_Addcommand 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.


RE: Camera parameters of retrieved camera item-Sam-12-15-2022

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)



RE: Camera parameters of retrieved camera item-Maarten-12-15-2022

Thank you Sam,cam_item.setParam('Open', 1)did the trick!