硬件准备

  • (1) 树莓派3 or 4
  • (2) 128G的SDCARD
  • (3) 16G的SDCARD
  • (4) SD卡读卡器

系统下载

https://www.raspberrypi.org/software/operating-systems/

config.txt 配置文件

由于默认镜像是关闭SSH,打开方法

在烧录后的SD卡根目录下建一个名字为ssh的空文件(没有扩展名)或者文件夹就可以了

修改密码

sudo raspi-config 第一项改密码 第二项设置hostname 比如 pinas 第三项设置无线,或者用后面的方法添加无线 第四项设置时区为上海 第五项打开camera

更新为国外镜像源

sudo sed -i 's#://raspbian.raspberrypi.org#s://mirrors.ustc.edu.cn/raspbian#g' /etc/apt/sources.list 
sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian#g' /etc/apt/sources.list.d/raspi.list

测试一下camera

通过camera捕获图像
raspistill -v -n -t 2000 -o shot.jpg

通过camera捕获视频
# 使用默认设置录制一段 5 秒钟的视频片段(1080p30)
raspivid -t 5000 -o video.h264 

将video.h264 转为.mp4
sudo apt-get install gpac
sudo MP4Box -add video.h264 video.mp4

参考:
https://blog.csdn.net/fhqlongteng/article/details/80433633

测试一下音频

拷贝一段视频上去,测试一下。使用系统的VLC播放器测试

安装golang

下载go1.15.6.linux-armv6l.tar.gz,解压到/home/pi/go 
建立工程目录 mkdir -p /home/pi/gopro 

vim /etc/profile
在最后添加
export GOROOT=/home/pi/go 
export GOPATH=/home/pi/gopro 
export GOPROXY=https://goproxy.cn,direct 
export GO111MODULE=on 
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
生效
source /etc/profile
测试
pi@camera:~$ go version
go version go1.15.6 linux/arm

安装gcc/git/curl/wget等工具

sudo apt install -y vim curl wget git build-essential

安装supervisor

sudo apt install -y supervisor

//启动frpc
sudo supervisorctl update

//修改配置后reload
sudo supervisorctl reload

安装frpc and clash

设置CURL代理

export http_proxy=http://127.0.0.1:7890
export https_proxy=https://127.0.0.1:7890

设置git代理

git config --global http.proxy socks5://127.0.0.1:7890

git config --global https.proxy socks5://127.0.0.1:7890

p7zip

sudo apt install p7zip-full

gocv安装

git clone https://github.com/hybridgroup/gocv.git
cd gocv
sudo make deps 
sudo make download
sudo make build_raspi


遇到错误
“/tmp/opencv/opencv_contrib-4.5.0/modules/xfeatures2d/src/boostdesc.cpp:654:20: fatal error: boostdesc_bgm.i: No such file or directory
           #include "boostdesc_bgm.i"”
		   
cd /tmp/opencv/opencv_contrib-4.5.0/modules/xfeatures2d/src/
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i
sudo wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i

make sudo_install

参考:
https://blog.csdn.net/z1314520cz/article/details/103501274

测试gocv

package main

import (
        "gocv.io/x/gocv"
)

func main() {
        webcam, _ := gocv.VideoCaptureDevice(0)
        window := gocv.NewWindow("Hello")
        img := gocv.NewMat()

        for {
                webcam.Read(&img)
                window.IMShow(img)
                window.WaitKey(1)
        }
}


32位linux系统会出现下面的错误,需要修改相应的代码才可以编译过
../../gopro/pkg/mod/gocv.io/x/gocv@v0.25.0/core.go:2009:16: type [1073741824]*_Ctype_char larger than address space
../../gopro/pkg/mod/gocv.io/x/gocv@v0.25.0/core.go:2009:16: type [1073741824]*_Ctype_char too large
修改
tmpslice := (*[1 << 30]*C.char)(unsafe.Pointer(strs.strs))[:length:length] 
为
tmpslice := (*[(1 << 29)-1]*C.char)(unsafe.Pointer(strs.strs))[:length:length] 

再次go build 
运行即可看到自己的视频了

参考:
https://github.com/docker/docker-credential-helpers/pull/61/files/cdde65956310ad369b40016dc7fff867b587877e