TA的每日心情 | 慵懒 昨天 16:31 |
---|
签到天数: 252 天 连续签到: 2 天 [LV.8]以坛为家I
|
【树莓派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 [options]...
- List USB devices
- -v, --verbose
- Increase verbosity (show descriptors)
- -s [[bus]:][devnum]
- Show only devices with specified device and/or
- bus numbers (in decimal)
- -d vendor:[product]
- 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 0x81 EP 1 IN
- bmAttributes 5
- Transfer Type Isochronous
- Synch Type Asynchronous
- Usage Type Data
- wMaxPacketSize 0x1400 3x 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[y:y + h, x:x + w] # 人脸区域
- 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
- [[[253 253 252]
- [253 253 252]
- [253 253 252]
- ...
- [253 253 252]
- [253 253 252]
- [253 253 252]]
- ...
- [[[253 253 252]
- [253 253 252]
- [253 253 252]
- ...
- [249 255 231]
- [248 255 220]
- [205 225 174]]
-
- [[ 76 90 70]
- [ 80 90 73]
- [ 86 93 80]
- ...
- [ 46 50 45]
- [ 46 48 43]
- [ 44 46 41]]
- [[ 80 93 75]
- [ 78 90 75]
- [ 83 92 79]
- ...
- [ 46 50 45]
- [ 44 49 47]
- [ 42 47 46]]
- [[ 82 92 75]
- [ 82 91 77]
- [ 78 88 80]
- ...
- [ 44 51 44]
- [ 42 47 45]
- [ 42 47 46]]]
-
- zhaomeijing@raspberrypi5:~/workspace/09_uvc$
复制代码//------测试结果: //------end
|
|