I am trying to have the camera display to simulate a vision pick and place.
I do not understand why when I change "while cam_item.setParam('isOpen') == '1':" to "while(1):" It'll constantly open a new window even though I never close it.
"while cam_item.setParam('isOpen') == '1':" will have 1 window and update properly.
#import_install('cv2', 'opencv-contrib-python')
import cv2 as cv
import numpy as np
import tempfile
import math
from robodk.robolink import * # RoboDK API
from robodk.robomath import * # Robot toolbox
from robodk.robodialogs import *
import time
# Settings
RDK = Robolink()
PROCESS_COUNT = -1 # How many frames to process before exiting. -1 means indefinitely.
# Camera
CAM_NAME = "Camera 1"
CAMERA_SIZE_X = 1280.0 # pixel
CAMERA_SIZE_Y = 720.0 # pixel
# Calculated frame and targets
#----------------------------------
# Get the simulated camera from RoboDK
cam_item = RDK.Item(CAM_NAME, ITEM_TYPE_CAMERA)
#camref = RDK.ItemUserPick('Select the Camera location (reference, tool or object)')
#cam_item = RDK.Cam2D_Add(camref, 'FOCAL_LENGTH=6 FOV=32 FAR_LENGTH=1000 SIZE=1280x720')
if not cam_item.Valid():
raise Exception("Camera not found! %s" % CAM_NAME)
cam_tool = cam_item.Parent()
if not cam_tool.Valid() or cam_tool.Type() != ITEM_TYPE_TOOL:
raise Exception("Camera parent is invalid, make sur it's a tool!")
tempdir = tempfile.gettempdir()
snapshot_file = tempdir + "\\sift_temp.png"
cam_item.setParam('Open', 1)
#----------------------------------------------
# Start a camera feed.
# If you are using a connected device, use cv.VideoCapture to get the livefeed.
#https://docs.opencv.org/master/d8/dfe/cl...pture.html
#
#capture = cv.VideoCapture(1)
# retval, image = capture.read()
#----------------------------------------------
# For now, we need to save RDK snapshots on disk.
# A new update is coming which will return the image, like: img = RDK.Cam2D_Snapshot('', cam_item)
#tempdir = tempfile.gettempdir()
#snapshot_file = tempdir + "\\sift_temp.png"
#----------------------------------------------
img = RDK.Cam2D_Snapshot('', cam_item)
# Process camera frames
img_scene = cv.imread(snapshot_file, cv.IMREAD_GRAYSCALE)
while cam_item.setParam('isOpen') == '1':
RDK。Cam2D_Snapshot (snapshot_file cam_item)
img_scene = cv.imread(snapshot_file, cv.IMREAD_GRAYSCALE)
cv.imshow('TEST',img_scene )
key = cv.waitKey(1)
if key == 27:
break # User pressed ESC, exit
cv.destroyAllWindows()
I do not understand why when I change "while cam_item.setParam('isOpen') == '1':" to "while(1):" It'll constantly open a new window even though I never close it.
"while cam_item.setParam('isOpen') == '1':" will have 1 window and update properly.
#import_install('cv2', 'opencv-contrib-python')
import cv2 as cv
import numpy as np
import tempfile
import math
from robodk.robolink import * # RoboDK API
from robodk.robomath import * # Robot toolbox
from robodk.robodialogs import *
import time
# Settings
RDK = Robolink()
PROCESS_COUNT = -1 # How many frames to process before exiting. -1 means indefinitely.
# Camera
CAM_NAME = "Camera 1"
CAMERA_SIZE_X = 1280.0 # pixel
CAMERA_SIZE_Y = 720.0 # pixel
# Calculated frame and targets
#----------------------------------
# Get the simulated camera from RoboDK
cam_item = RDK.Item(CAM_NAME, ITEM_TYPE_CAMERA)
#camref = RDK.ItemUserPick('Select the Camera location (reference, tool or object)')
#cam_item = RDK.Cam2D_Add(camref, 'FOCAL_LENGTH=6 FOV=32 FAR_LENGTH=1000 SIZE=1280x720')
if not cam_item.Valid():
raise Exception("Camera not found! %s" % CAM_NAME)
cam_tool = cam_item.Parent()
if not cam_tool.Valid() or cam_tool.Type() != ITEM_TYPE_TOOL:
raise Exception("Camera parent is invalid, make sur it's a tool!")
tempdir = tempfile.gettempdir()
snapshot_file = tempdir + "\\sift_temp.png"
cam_item.setParam('Open', 1)
#----------------------------------------------
# Start a camera feed.
# If you are using a connected device, use cv.VideoCapture to get the livefeed.
#https://docs.opencv.org/master/d8/dfe/cl...pture.html
#
#capture = cv.VideoCapture(1)
# retval, image = capture.read()
#----------------------------------------------
# For now, we need to save RDK snapshots on disk.
# A new update is coming which will return the image, like: img = RDK.Cam2D_Snapshot('', cam_item)
#tempdir = tempfile.gettempdir()
#snapshot_file = tempdir + "\\sift_temp.png"
#----------------------------------------------
img = RDK.Cam2D_Snapshot('', cam_item)
# Process camera frames
img_scene = cv.imread(snapshot_file, cv.IMREAD_GRAYSCALE)
while cam_item.setParam('isOpen') == '1':
RDK。Cam2D_Snapshot (snapshot_file cam_item)
img_scene = cv.imread(snapshot_file, cv.IMREAD_GRAYSCALE)
cv.imshow('TEST',img_scene )
key = cv.waitKey(1)
if key == 27:
break # User pressed ESC, exit
cv.destroyAllWindows()