计算与英特尔Realsense R200深度摄像头的距离 [英] Calculating distance from Intel Realsense R200 Depth Camera
问题描述
我一直在尝试使用R200相机的值计算物体的距离.我安装了PyRealsense和librealsense(旧版).而且PyRealsense的示例可以正常工作.
I have been trying to calculate the distances of objects with values of R200 camera. I installed PyRealsense and librealsense(legacy). And examples of PyRealsense are working without any problem.
我为此创建了一个代码:
I have created a code for this purpose:
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)
它返回一个矩阵,其值根据对象的位置而变化:
It returns a matrix that values changing with depending on the position of the object:
[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]
此矩阵的哪一列代表距离值,或者该怎么计算距离.
Which column of this matrix is represent distance value or what should I do to calculate the distance.
推荐答案
在Google上进行搜索时,我发现了一个使用RealSense摄像机计算距离计算的示例:
While searching on Google, I have found an example for calculatin distance with RealSense camera:
https://github.com/intel/intel-iot-refkit/blob/master/meta-refkit-extra/doc/computervision.rst
我必须对其进行编辑才能使其与PyRealSense 2.0兼容:
I had to edit it to make it work with 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的最简单方法是什么.
It calculates distance when it shows a cat face. I have started to learn Tensorflow and my knowledge about OpenCV is poor. Can you explain me, what is the easiest way to port this code to TensorFlow or CAFFE.
这篇关于计算与英特尔Realsense R200深度摄像头的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!