赵美京₁₉⁸⁸⁸ 发表于 2024-4-30 16:38:45

【树莓派5 测评】 + 12.UVC扩展功能测试(zmj)

【树莓派5 测评】 + 12.UVC扩展功能测试(zmj)
UVC的有很多好玩的地方,继续推一篇关于UVC的功能测试。1.        借助lsusb检测UVC更多信息以前没有着重留意“lsusb”的扩展功能,这次发现它的功能十分强大。//------指令lsusb
//---基础功能:lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 1b3f:2008 Generalplus Technology Inc. Usb Audio Device
Bus 001 Device 003: ID 0c45:6362 Microdia USB 2.0 Camera
Bus 001 Device 002: ID 1a40:0801 Terminus Technology Inc. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
//---检查接口设备速率:lsusb -t
/:Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
/:Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
    |__ Port 2: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
      |__ Port 1: Dev 3, If 0, Class=Video, Driver=uvcvideo, 480M
      |__ Port 1: Dev 3, If 1, Class=Video, Driver=uvcvideo, 480M
      |__ Port 3: Dev 4, If 2, Class=Audio, Driver=snd-usb-audio, 12M
      |__ Port 3: Dev 4, If 0, Class=Audio, Driver=snd-usb-audio, 12M
      |__ Port 3: Dev 4, If 3, Class=Human Interface Device, Driver=usbhid, 12M
//---查看更详细信息:lsusb -v -s 001:003
Bus 001 Device 003: ID 0c45:6362 Microdia USB 2.0 Camera
Couldn't open device, some information will be missing
Device Descriptor:
bLength                18
bDescriptorType         1
bcdUSB               2.00
bDeviceClass          239 Miscellaneous Device
bDeviceSubClass         2
bDeviceProtocol         1 Interface Association
bMaxPacketSize0      64
idVendor         0x0c45 Microdia
idProduct          0x6362
bcdDevice            0.00
iManufacturer         2 Sonix Technology Co., Ltd.
iProduct                1 USB 2.0 Camera
iSerial               0
bNumConfigurations      1
...
//------Log信息
zhaomeijing@raspberrypi5:~/workspace/09_uvc$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 1b3f:2008 Generalplus Technology Inc. Usb Audio Device
Bus 001 Device 003: ID 0c45:6362 Microdia USB 2.0 Camera
Bus 001 Device 002: ID 1a40:0801 Terminus Technology Inc. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
zhaomeijing@raspberrypi5:~/workspace/09_uvc$ lsusb -h
Usage: lsusb ...
List USB devices
-v, --verbose
      Increase verbosity (show descriptors)
-s [:]
      Show only devices with specified device and/or
      bus numbers (in decimal)
-d vendor:
      Show only devices with the specified vendor and
      product ID numbers (in hexadecimal)
-D device
      Selects which device lsusb will examine
-t, --tree
      Dump the physical USB device hierarchy as a tree
-V, --version
      Show version of program
-h, --help
      Show usage and help
zhaomeijing@raspberrypi5:~/workspace/09_uvc$ lsusb -t
/:Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
/:Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
    |__ Port 2: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
      |__ Port 1: Dev 3, If 0, Class=Video, Driver=uvcvideo, 480M
      |__ Port 1: Dev 3, If 1, Class=Video, Driver=uvcvideo, 480M
      |__ Port 3: Dev 4, If 2, Class=Audio, Driver=snd-usb-audio, 12M
      |__ Port 3: Dev 4, If 0, Class=Audio, Driver=snd-usb-audio, 12M
      |__ Port 3: Dev 4, If 3, Class=Human Interface Device, Driver=usbhid, 12M
zhaomeijing@raspberrypi5:~/workspace/09_uvc$ lsusb -v -s 001:003

Bus 001 Device 003: ID 0c45:6362 Microdia USB 2.0 Camera
Couldn't open device, some information will be missing
Device Descriptor:
bLength                18
bDescriptorType         1
bcdUSB               2.00
bDeviceClass          239 Miscellaneous Device
bDeviceSubClass         2
bDeviceProtocol         1 Interface Association
bMaxPacketSize0      64
idVendor         0x0c45 Microdia
idProduct          0x6362
bcdDevice            0.00
iManufacturer         2 Sonix Technology Co., Ltd.
iProduct                1 USB 2.0 Camera
iSerial               0
bNumConfigurations      1
    Interface Descriptor:
      bLength               9
      bDescriptorType         4
      bInterfaceNumber      1
      bAlternateSetting       6
      bNumEndpoints         1
      bInterfaceClass      14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface            0
      Endpoint Descriptor:
      bLength               7
      bDescriptorType         5
      bEndpointAddress   0x81EP 1 IN
      bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
      wMaxPacketSize   0x14003x 1024 bytes
      bInterval               1
zhaomeijing@raspberrypi5:~/workspace/09_uvc$2.        借助OpenCV实现便捷的RGB与灰度转换下面的代码可捕捉UVC生成的视频流,用BGR颜色和灰色模式展示。//------测试指令
python3 ./uvc_gray.py
注:测试界面按“Q”退出,或者指令界面“Ctrl + C”退出。
//------Log信息
zhaomeijing@raspberrypi5:~/workspace/09_uvc$ python3 ./uvc_gray.py
[ WARN:0@1.217] global ./modules/videoio/src/cap_gstreamer.cpp (1405) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
zhaomeijing@raspberrypi5:~/workspace/09_uvc$
//------源码:OpenCV实现UVC灰度转换
import numpy as np
import cv2

cap = cv2.VideoCapture(0)
cap.set(3,640) # set Width
cap.set(4,480) # set Height

while(True):
    ret, frame = cap.read()
    frame = cv2.flip(frame, -1) # Flip camera vertically
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
   
    cv2.imshow('frame', frame)
    cv2.imshow('gray', gray)
   
    k = cv2.waitKey(30) & 0xff
    if k == 27: # press 'ESC' to quit
      break

cap.release()
cv2.destroyAllWindows()//------测试结果:3.        人脸检测人脸检测有多种方式实现,此处通过python实现。//------测试指令
python3 ./face_detect.py
注:测试界面按“Q”退出,或者指令界面“Ctrl + C”退出。
//------源码
import cv2

# 导入人脸级联分类器,'.xml'文件里包含训练出来的人脸特征
#face_engine = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
face_engine = cv2.CascadeClassifier('/usr/share/opencv4/haarcascades/haarcascade_frontalface_alt.xml')
#/usr/share/opencv4/haarcascades/haarcascade_frontalface_alt.xml

# 导入人眼级联分类器,'.xml'文件里包含训练出来的人眼特征
eye_cascade = cv2.CascadeClassifier('/usr/share/opencv4/haarcascades/haarcascade_eye.xml')
#/usr/share/opencv4/haarcascades/haarcascade_eye.xml

# 调用摄像头(读取/ect中的驱动);这里索引是0的原因是添加过驱动了;
cap = cv2.VideoCapture(0)
while (True):
    # 获取摄像头拍摄到的画面
    # 会得到两个参数,一个是否捕捉到图像(True/False),另一个为存放每帧的图像
    ret, frame = cap.read()# 读取一帧图像
    # 每帧图像放大1.1倍,重复检测10次
    faces = face_engine.detectMultiScale(frame, 1.1, 10)# 得到人脸,可能不止一个
    img = frame# 复制
    print(img)
    for (x, y, w, h) in faces:
      # 画出人脸框,蓝色,画笔宽度为2
      img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
      # 框选出人脸区域,在人脸区域而不是全图中进行人眼检测,节省计算资源
      face_area = img# 人脸区域
      eyes = eye_cascade.detectMultiScale(face_area, 1.1, 5)
      # 用人眼级联分类器在人脸区域进行人眼识别,返回的eyes为眼睛坐标列表
      for (ex, ey, ew, eh) in eyes:
            # 画出人眼框,绿色,画笔宽度为1
            cv2.rectangle(face_area, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 1)

    # 实时展示效果画面
    #cv2.imshow(''frame'', img)
    cv2.imshow('frame', img)
    # 每5毫秒监听一次键盘动作
    if cv2.waitKey(5) & 0xFF == ord('q'):# 当按下“q”键时退出人脸检测
      break

# 最后,关闭所有窗口
cap.release()
cv2.destroyAllWindows()# 释放资源
//------Log信息
zhaomeijing@raspberrypi5:~/workspace/09_uvc$ python3 ./face_detect.py
Xlib:extension "DRI2" missing on display "localhost:11.0".
Xlib:extension "DRI2" missing on display "localhost:11.0".
[ WARN:0@3.464] global ./modules/videoio/src/cap_gstreamer.cpp (1405) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
[[


...


]
...

[[


...


]

[[ 769070]
[ 809073]
[ 869380]
...
[ 465045]
[ 464843]
[ 444641]]

[[ 809375]
[ 789075]
[ 839279]
...
[ 465045]
[ 444947]
[ 424746]]

[[ 829275]
[ 829177]
[ 788880]
...
[ 445144]
[ 424745]
[ 424746]]]

zhaomeijing@raspberrypi5:~/workspace/09_uvc$//------测试结果://------end
页: [1]
查看完整版本: 【树莓派5 测评】 + 12.UVC扩展功能测试(zmj)

Baidu
map