计算与Intel Realsense R200深度凸轮的距离

2024-05-16 11:20:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试用R200相机来计算物体的距离。我安装了PyRealsense和librealsense(legacy)。而pyeralsense的例子却没有任何问题。在

我为此创建了一个代码:

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) 

它返回一个矩阵,该矩阵的值随对象的位置而变化:

^{pr2}$

这个矩阵的哪一列代表距离值,或者我应该如何计算距离。在


Tags: devimport距离streamaswith矩阵pyrs
1条回答
网友
1楼 · 发布于 2024-05-16 11:20:07

在谷歌上搜索时,我发现了一个使用RealSense摄像头计算距离的例子:

https://github.com/intel/intel-iot-refkit/blob/master/meta-refkit-extra/doc/computervision.rst

我不得不对其进行编辑以使其与PyralSense 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的最简单方法是什么。在

相关问题 更多 >