ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

树莓派ARM64系统中如何设置opencv-python读取高清摄像头画面

2022-01-16 20:58:21  阅读:214  来源: 互联网

标签:树莓 python cap cv2 opencv camera https time


问题

树莓派4B 8G,2021-10-30-raspios-bullseye-arm64.imgLinux raspberrypi 5.10.63-v8+ #1459 SMP PREEMPT Wed Oct 6 16:42:49 BST 2021 aarch64 GNU/Linux,用vcgencmd get_camera监测,输出support=0 detected=0
发现使用miniconda安装的python 3.9中读取树莓派4B摄像头帧时只能以480p分辨率读取,就算代码中定义了cap的长宽也无法获取其他分辨率的图片。
树莓派的ARM64位系统用的是Bullseye版本,其中没有raspistill库,因为新版本系统舍弃了旧版本的驱动(New default camera subsystem based on libcamera. New camera demo applications (libcamera-still and libcamera-vid) have replaced raspistill and raspivid),并且我尝试自己编译userland libraries(https://github.com/robidouille/robidouille/tree/master/raspicam_cv)是提示不支持64位系统,所以转而寻找其他方法。
树莓派的ARM64位系统也不支持picamera库,缺少’libmmal.so’库的32位支持。因此,只能从驱动和opencv下手。

解决方案

/boot/config.txtcamera_auto_detect=1注释掉,加入start_x=1,设置 gpu_mem=512 ;将/etc/modules中只保留i2c-dev

sudo nano  /boot/config.txt
    # Automatically load overlays for detected cameras
    #camera_auto_detect=1   注释这一行
    start_x=1    			加入这一行
    gpu_mem=512   			大于128即可

sudo nano /etc/modules
    i2c-dev
    #bcm2835-v4l2

conda install opencv
vcgencmd get_camera
import cv2, time
# cap = cv2.VideoCapture('/dev/video0', cv2.CAP_V4L)
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2592)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1944)
# cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))

t=time.time()
for i in range(10):
    ret, frame = cap.read()
print((time.time()-t)/10,'s')
print(ret, frame.shape)
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.imwrite('/home/pi/Desktop/image.jpg', frame)
cap.release()

参考资料

https://zhuanlan.zhihu.com/p/435575418
https://www.raspberrypi.com/documentation/accessories/camera.html#python-bindings-for-libcamera
https://blog.forgiveher.cn/posts/1574671872/
https://github.com/kabelhorst/userland
https://github.com/robidouille/robidouille/tree/master/raspicam_cv

官方文档提到

To override the automatic camera detection, Bullseye users will also need to delete the entry
camera_auto_detect=1
if present in the config.txt file. If you need to do edit this file then your Raspberry Pi will need to be rebooted. Setting camera_auto_detect=0 disables the boot time detection completely.

标签:树莓,python,cap,cv2,opencv,camera,https,time
来源: https://blog.csdn.net/Straka/article/details/122528281

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有