行车记录仪

摄像头

树莓派外接摄像头有两种一般法,一种是通过USB,这种比较常用,另一种是通过CIS,这种事树莓派官方自带的方法,我就是通过这种接口外接摄像头获取图片的

注意方向别插反了,摄像头排线金属的朝金属的一方,插好硬件后

raspi-config```
1
2

选5```interfacing options

接着选1 Camera选择enable,系统会提示重启,重启后就可以了

获取图片

这部分采用最简单的raspistill工具获取

获取的shell命令为

-o image.jpg -t 1000```
1
2

程序设置每秒取一张图片,代码如下

import os
import shutil
import time
from datetime import datetime,timedelta

if name == ‘main‘:
TIME_DALTA = 1
while True:
save_root = “/home/pi/Videos/save_images/“
time_now = datetime.now()
N_days_ago = time_now + timedelta(days=-TIME_DALTA)
year_month_day = str(time_now.year) + “-“ + str(time_now.month) + “-“ + str(time_now.day)
year_month_day_N = str(N_days_ago.year) + “-“ + str(N_days_ago.month) + “-“ + str(N_days_ago.day)
hour_min_sec = str(time_now.hour) + “-“ + str(time_now.minute) + “-“ + str(time_now.second)
root_dir = os.path.join(save_root, year_month_day)
root_dir_N = os.path.join(save_root, year_month_day_N)
if os.path.isdir(root_dir_N):
shutil.rmtree(root_dir_N,True)
save_path = os.path.join(root_dir, hour_min_sec) + “.jpg”
if not os.path.exists(root_dir):
os.mkdir(root_dir)
try:
time_start = datetime.now()
print(“++++++++++++++++++++++save path: “, save_path)
print(“start time: “, time_start)
cmd = “raspistill -t 1000 -o {}”.format(save_path)
time_end = datetime.now()
print(“end time: “, time_end)
os.system(cmd)

    # time.sleep(1)
except:
    print("get image failed")
1
2
3
4
5
6

### 开机自动运行

因为没接口控制什么时候开始,什么时候结束,就设置为开机程序自动运行

```sudo vim /etc/rc.local

添加启动命令

python save_video_from_rtsp.py > save_log.txt 2>&1 &```
1
2
3
4
5
6

### 环境问题

- pip安装包的时候报memoryerror,原因是树莓派3b的内存只有1G,解决办法是增加SWAP空间

```cd /var

先关闭

swapofflink
1
2
3
4

重新设置swap大小

```sudo dd if=/dev/zero of=swap bs=1M count=1024

格式化

mkswaplink
1
2
3
4

开启

```sudo swapon /var/swap

通过free -m查看

参考

  1. opencv+picamera

    本打算用opencv+picamera来执行的,但是装不上opencv,装不上cv2所需要的numpy,报错ModuleNotFoundError: No module named 'numpy.core._multiarray_umath 一直没有解决,缺失libcblas时参考了:https://blog.csdn.net/kevindree/article/details/88772691

    想参考未参考上的:http://www.voidcn.com/article/p-gcmfibth-bmp.html

    https://blog.csdn.net/qq_35987777/article/details/97919963

  2. raspistill

    参考了:https://www.cnblogs.com/jikexianfeng/p/7130843.html, 也可以raspistill –help

    获取图片:https://www.cnblogs.com/uestc-mm/p/7587783.html