#Realsense后端-使用后端接口控制设备

解决pybackend问题链接

Solved: Enable Auto-Exposure Using Python Code - Intel Communities

后端控制代码

import pybackend2 as rs
import time

def on_frame(profile,f):
    print ("收到 %d个字节" % f.frame_size)
    # Accessing image pixels
    p = f.pixels
    print ("前十个字节是: ")
    for i in range(10):
        print (hex(p[i]))
    print(profile)


try:
    # ==============建立设备====================
    backend = rs.create_backend()
    infos = backend.query_uvc_devices()
    print(infos)
    print("有%d 个连接 UVC 的设备" % len(infos))
    if len(infos) is 0: exit(1)
    info = infos[2]
    dev = backend.create_uvc_device(info)

    print ("VID=%d, PID=%d, MI=%d, UID=%s" % (info.vid, info.pid, info.mi, info.unique_id))

    # =================打开电源=============
    print ("打开电源...")
    dev.set_power_state(rs.D0)

    # ===================配置流=================
    print ("打印设备支持的UVC配置文件列表...")
    profiles = dev.get_profiles()
    vga=0
    for p in profiles:
        print (p)
        # 保存 IR VGA 设置为稍后
        if p.width == 640 and p.height == 480 and p.fps == 30:
            vga = p
    first = profiles[0]

    print ("协商Probe-Commit的第一个配置文件....")
    dev.probe_and_commit(first,callback=on_frame)#回调函数

    #======================深度相机曝光度=====================
    #定义 深度相机曝光度
    xu = rs.extension_unit(0, 3, 2, rs.guid("C9606CCB-594C-4D25-af47-ccc496435995")) # Define the Depth XU
    #初始化 depth XU
    #dev.init_xu(xu)
    #ae = dev.get_xu(xu, 0xB, 1) # get XU value. args: XU, control #, # of bytes
    #print ("Auto Exposure option is:", ae)
    #print ("Setting Auto Exposure option to new value")
    #dev.set_xu(xu, 0x0B, [0x00]) # set XU value. args: XU, control #, list of bytes
    # ae = dev.get_xu(xu, 0xB, 1)
    # print ("New Auto Exposure setting is:", ae)

    #====================PU 控制=================================
    gain = dev.get_pu(rs.option.gain)
    print ("Gain = %d" % gain)
    print ("将gain设置新值:")
    #dev.set_pu(rs.option.gain, 32)
    gain = dev.get_pu(rs.option.gain)
    print ("New gain = %d" % gain)

    # ======================开始流==============================
    print ("'开始回调(所有引脚):")
    dev.start_callbacks()

    print ("开始流(从所有引脚)..")
    dev.stream_on()

    print ("等待5秒,等待帧:")
    time.sleep(5)

    # =======================关闭设备=========================
    print ("停止读取新的回调….")
    dev.stop_callbacks()

    print ("关闭特定的引脚....")
    dev.close(first)

    # 将帧保存到磁盘
    def save_frame(profile, f):
        f.save_png("pybackend_example_1_general_depth_frame.png", 640, 480, f.frame_size / (640*480))

    print ("使用配置文件保存IR VGA帧:", vga)
    dev.probe_and_commit(vga, save_frame)
    #重新打开自动曝光
    # dev.set_xu(xu, 0x0B, [0x01])
    dev.start_callbacks()
    dev.stream_on()
    time.sleep(1)
    dev.close(vga)

    print ("Move device to D3")
    dev.set_power_state(rs.D3)
    pass
except Exception as e:
    print (e)
    pass

关于UVC: USB 视频类,是一种为USB视频捕获设备定义的协议标准。VideoControl(VC)Interface和VideoStream(VS) Interface是其中基本的intelface。VCInterface用于进行配置,操控,设置UVC设备进入不同的功能状态,而VSInterface则负责视频数据流的传输。

大概解释:(84条消息) UVC(USB Video Class)协议讲解_LinuxWorking的博客-CSDN博客_uvc协议

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...