OK3588运行python程序读取usb摄像头
- 硬件连接
- 用工具测试验证摄像头工作正常
- python 读取usb摄像头并进行图像处理
 
硬件连接
把usb摄像头插入HOST的usb接口。
 在串口终端运行
 sudo v4l2-ctl --list-devices
 如下图
 
 当前的usb设备是 /dev/video74
用工具测试验证摄像头工作正常
远程访问开发板
 用cheese打开/dev/video74
 运行 cheese /dev/video74
 运行结果如图
 
 说明usb摄像头工作正常。
python 读取usb摄像头并进行图像处理
安装必要的软件包
 sudo apt-get install python3-opencv -y
 sudo apt-get install python3-matplotlib -y
#coding:utf-8
import cv2
cap=cv2.VideoCapture(74)
index=1
while(cap.isOpened()):
  ret,frame = cap.read()
  cv2.imshow("src_image",frame)
  flip=cv2.flip(frame,0)
  cv2.imshow("flip_image",flip)
  gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
  cv2.imshow("gray_image",gray)
  ret,threshold=cv2.threshold(gray,140,255,0,gray)
  
  edges = cv2.Canny(gray, 100, 200)
  
  cv2.imshow("edges_image",edges)
  k=cv2.waitKey(1) & 0xFF
  if k == ord('s'):
    cv2.imwrite("./"+str(index)+".jpg",frame)
    index+=1
  elif k == ord('q'):
    break
cap.release()
cv2.destroyAllWindows()
编辑上面的代码保存成video.py文件,并运行
 python3 video.py
 运行效果如下:
 四个画面:原图图像,翻转图像,灰度图像和边缘检测图像。
 











![[golang gin框架] 40.Gin商城项目-微服务实战之Captcha验证码微服务](https://img-blog.csdnimg.cn/img_convert/57a89a899894d60f20d39f5c84fde3b5.png)


![学习babylon.js --- [1] 初次体验和安装](https://img-blog.csdnimg.cn/f9a69cb3cb214b75af9ba4dbffa98961.png)




