我一直试图用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]这个矩阵的哪一列表示距离值,或者我应该如何计算距离。
发布于 2018-06-23 19:31:22
在谷歌上搜索时,我找到了一个用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的最简单方法是什么?
https://stackoverflow.com/questions/50802333
复制相似问题