Python 计算与Intel Realsense R200深度相机的距离
我一直试图用R200摄像机的值计算物体的距离。我安装了PyRealsense和librealsense(遗留)。PyRealsense的例子工作起来没有任何问题 我为此目的创建了一个代码:Python 计算与Intel Realsense R200深度相机的距离,python,formula,realsense,Python,Formula,Realsense,我一直试图用R200摄像机的值计算物体的距离。我安装了PyRealsense和librealsense(遗留)。PyRealsense的例子工作起来没有任何问题 我为此目的创建了一个代码: import pyrealsense as pyrs from pyrealsense.constants import rs_option depth_stream = pyrs.stream.DepthStream() infrared_stream = pyrs.stream.InfraredStrea
import pyrealsense as pyrs
from pyrealsense.constants import rs_option
depth_stream = pyrs.stream.DepthStream()
infrared_stream = pyrs.stream.InfraredStream()
with pyrs.Service() as serv:
with serv.Device(streams=(depth_stream, infrared_stream, )) as dev:
#dev.apply_ivcam_preset(0)
while True:
dev.wait_for_frames()
print(dev.infrared)
它返回一个矩阵,该矩阵的值随对象的位置而变化:
[37 37 39 ... 20 20 21]
[35 35 38 ... 17 18 19]
[34 33 37 ... 19 20 20]]
[[40 36 30 ... 16 15 17]
[40 37 28 ... 14 14 19]
[42 39 28 ... 14 16 20]
此矩阵的哪列表示距离值,或者我应该如何计算距离。在Google上搜索时,我发现了一个使用RealSense camera计算距离的示例: 我必须对其进行编辑,使其与PyRealSense 2.0兼容:
#!/usr/bin/python3
import sys
import numpy as np
import cv2
import pyrealsense as pyrs
with pyrs.Service() as serv:
serv.start()
with serv.Device() as cam:
cat_cascade = cv2.CascadeClassifier("/usr/share/opencv/haarcascades/haarcascade_frontalcatface.xml")
for x in range(30):
# stabilize exposure
cam.wait_for_frames()
while True:
# get image from web cam
cam.wait_for_frames()
img = cam.color
cats = cat_cascade.detectMultiScale(img)
for (x,y,w,h) in cats:
# find center
cx = int(round(x+(w/2)))
cy = int(round(y+(h/2)))
depth = cam.depth[cy][cx]
print("Cat found, distance " + str(depth/10.0) + " cm")
当它显示猫脸时,它计算距离。我已经开始学习Tensorflow,但我对OpenCV的了解很差。你能给我解释一下,把代码移植到TensorFlow或CAFFE的最简单方法是什么吗 您必须创建一个答案并将其标记为正确,而不是编辑您的问题并在标题中添加[已解决],这是表明问题已在SO中解决的正确方式