我一直在尝试使用R200相机的值来计算物体的距离。我安装了PyRealsense和librealsense(遗留)。 PyRealsense的例子没有任何问题。
我为此创建了一个代码:
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]
此矩阵的哪一列表示距离值,或者我应该怎样做以计算距离。
答案 0 :(得分:0)
在Google上进行搜索时,我发现了一个使用RealSense摄像机计算钙距的示例:
https://github.com/intel/intel-iot-refkit/blob/master/meta-refkit-extra/doc/computervision.rst
我必须对其进行编辑才能使其与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的最简单方法是什么。