12-05-2019,上午09:16
你好,
我有下面的Python代码,如果我没有roboDK运行它,它可以完美地工作。如果我将它导入到roboDK并从那里运行它,它会返回我一个错误(附加的图像),因为库不是roboDK的。你知道我该怎么解决吗?
代码:
导入cv2 #最先进的计算机视觉算法库
导入numpy作为科学计算的nnp # basic包
进口imageio
进口matplotlib。pyplot作为plt# 2D绘图库,生成发布质量图
将pyrealsense2导入为rs
进口win32gui
进口win32api
导入的时间
进口pyautogui
从robolink导入* # API与RoboDK通信
从robodk导入* #基本矩阵操作
任何与RoboDK的互动都必须通过
RL = Robolink()
积分= rs.points()
Pipe = rs.pipeline()
Config = rs.config()
Profile = pipe.start(config)
Colorizer = rs.colorizer()
Align = rs.align(rs.stream.color)
state_left = win32api.GetKeyState(0x01) #左按钮向上= 0或1。Button down = -127或-128
设备= profile.get_device() #类型:rs.device
Depth_sensor = device.first_depth_sensor() #类型:rs.depth_sensor
如果depth_sensor.supports (rs.option.depth_units):
depth_sensor.set_option (rs.option.depth_units, 0.0001)
robot = RL.Item('UR5e')
frame = RL。项目(“参照系”)
目标= RL。AddTarget('Target 2', frame)
试一试:
而真正的:
Frames = pipe.wait_for_frames()
帧= align.process(帧)
Depth_frame = frames.get_depth_frame()
Color_frame = frames.get_color_frame()
如果不是depth_frame:继续
#打印(宽度、高度)
Depth = np.asanyarray(colorizer.colorize(depth_frame).get_data()))
Color = np.asanyarray(color_frame.get_data())
图片= np。hstack((颜色、深度))
# cv2.namedWindow (RGB_View, cv2.WINDOW_NORMAL)
# cv2。cv2 setWindowProperty(“RGB_View”。WND_PROP_FULLSCREEN cv2.WINDOW_FULLSCREEN)
cv2。imshow (RGB_View,颜色)
Depth_intrin = depth_frame.profile.as_video_stream_profile().intrinsic
#flags, hcursor, (x,y) = win32gui.GetCursorInfo()
x, y = win32api.GetCursorPos()
#打印(x, y)
Pixel_coord = [x, y]
keypressed = win32api.GetKeyState(0x01)
key = cv2.waitKey(1)
#按“esc”或“q”关闭图像窗口
if key & 0xFF == ord('q')或key == 27:
cv2.destroyAllWindows ()
打破
#计算距离
如果keypressed != state_left:
State_left = keypressed
打印(keypressed)
如果按键< 0:
如果(0Dist_to_center = depth_frame.get_distance(x,y)
Dist_to_center = round(Dist_to_center, 4)
Depth_point = rs.rs2_deproject_pixel_to_point(depth_intrin, pixel_coord, dist_to_center)
[i * 100 for i in Depth_point]
ddepth_point = [round(i, 3) for i in Depth_point]
#depth_point =(", "。Join (repr(e) for e in depth_point))
open('Coordinates.txt', 'w') as f:
F.write ("%s\n" % depth_point)
f.close ()
打印(depth_point)
#print(depth_point[0:5], depth_point[7:12], depth_point[15:19])
print('相机正对着一个对象:',dist_to_center,'米远')
Target.setPose(Offset(eye(), depth_point[0], depth_point[1], depth_point[2], 0,0,0))
robot.MoveL(目标)
time . sleep (0.7)
最后:
pipe.stop ()
我有下面的Python代码,如果我没有roboDK运行它,它可以完美地工作。如果我将它导入到roboDK并从那里运行它,它会返回我一个错误(附加的图像),因为库不是roboDK的。你知道我该怎么解决吗?
代码:
导入cv2 #最先进的计算机视觉算法库
导入numpy作为科学计算的nnp # basic包
进口imageio
进口matplotlib。pyplot作为plt# 2D绘图库,生成发布质量图
将pyrealsense2导入为rs
进口win32gui
进口win32api
导入的时间
进口pyautogui
从robolink导入* # API与RoboDK通信
从robodk导入* #基本矩阵操作
任何与RoboDK的互动都必须通过
RL = Robolink()
积分= rs.points()
Pipe = rs.pipeline()
Config = rs.config()
Profile = pipe.start(config)
Colorizer = rs.colorizer()
Align = rs.align(rs.stream.color)
state_left = win32api.GetKeyState(0x01) #左按钮向上= 0或1。Button down = -127或-128
设备= profile.get_device() #类型:rs.device
Depth_sensor = device.first_depth_sensor() #类型:rs.depth_sensor
如果depth_sensor.supports (rs.option.depth_units):
depth_sensor.set_option (rs.option.depth_units, 0.0001)
robot = RL.Item('UR5e')
frame = RL。项目(“参照系”)
目标= RL。AddTarget('Target 2', frame)
试一试:
而真正的:
Frames = pipe.wait_for_frames()
帧= align.process(帧)
Depth_frame = frames.get_depth_frame()
Color_frame = frames.get_color_frame()
如果不是depth_frame:继续
#打印(宽度、高度)
Depth = np.asanyarray(colorizer.colorize(depth_frame).get_data()))
Color = np.asanyarray(color_frame.get_data())
图片= np。hstack((颜色、深度))
# cv2.namedWindow (RGB_View, cv2.WINDOW_NORMAL)
# cv2。cv2 setWindowProperty(“RGB_View”。WND_PROP_FULLSCREEN cv2.WINDOW_FULLSCREEN)
cv2。imshow (RGB_View,颜色)
Depth_intrin = depth_frame.profile.as_video_stream_profile().intrinsic
#flags, hcursor, (x,y) = win32gui.GetCursorInfo()
x, y = win32api.GetCursorPos()
#打印(x, y)
Pixel_coord = [x, y]
keypressed = win32api.GetKeyState(0x01)
key = cv2.waitKey(1)
#按“esc”或“q”关闭图像窗口
if key & 0xFF == ord('q')或key == 27:
cv2.destroyAllWindows ()
打破
#计算距离
如果keypressed != state_left:
State_left = keypressed
打印(keypressed)
如果按键< 0:
如果(0
Dist_to_center = round(Dist_to_center, 4)
Depth_point = rs.rs2_deproject_pixel_to_point(depth_intrin, pixel_coord, dist_to_center)
[i * 100 for i in Depth_point]
ddepth_point = [round(i, 3) for i in Depth_point]
#depth_point =(", "。Join (repr(e) for e in depth_point))
open('Coordinates.txt', 'w') as f:
F.write ("%s\n" % depth_point)
f.close ()
打印(depth_point)
#print(depth_point[0:5], depth_point[7:12], depth_point[15:19])
print('相机正对着一个对象:',dist_to_center,'米远')
Target.setPose(Offset(eye(), depth_point[0], depth_point[1], depth_point[2], 0,0,0))
robot.MoveL(目标)
time . sleep (0.7)
最后:
pipe.stop ()