face_recognition移植至树莓派

在linxu环境下实现了face_recognition的运行后(参考:https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65 ,切记勿按该文档的说明去安装PIXEL这个GUI,否则会灰屏卡死,然后重装

1. 制作启动盘

1.1  下载镜像

https://www.raspberrypi.org/downloads/raspbian/

最好下载一个带桌面的版本

1.2 烧录镜像

下载一个win32 disk imager 专门用来写“.img”

格式化 /  烧录

格式化软件可选:SD formatter

烧录软件可选:win32diskimager

烧录完成的tf卡已经在电脑上显示为boot了,拔出tf并插入树莓派板中,启动:

按提示 依次修改密码 / 选择一个wifi / 地区选择 / 软件升级

 

2. 配置

2.1 

(参考:https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65 ,切记勿按该文档的说明去安装PIXEL这个GUI,否则会灰屏卡死,然后重装

通过上一步完成基本的配置后,开启一个terminal即可按步骤进行配置。

Install required libraries with these commands:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential \
    cmake \
    gfortran \
    git \
    wget \
    curl \
    graphicsmagick \
    libgraphicsmagick1-dev \
    libatlas-dev \
    libavcodec-dev \
    libavformat-dev \
    libboost-all-dev \
    libgtk2.0-dev \
    libjpeg-dev \
    liblapack-dev \
    libswscale-dev \
    pkg-config \
    python3-dev \
    python3-numpy \
    python3-pip \
    zip
sudo apt-get clean

Install the picamera python library with array support (if you are using a camera):

sudo apt-get install python3-picamera
sudo pip3 install --upgrade picamera[array]

Temporarily enable a larger swap file size (so the dlib compile won't fail due to limited memory):

sudo nano /etc/dphys-swapfile

< change CONF_SWAPSIZE=100 to CONF_SWAPSIZE=1024 and save / exit nano >

sudo /etc/init.d/dphys-swapfile restart

Download and install dlib v19.6:

mkdir -p dlib
git clone -b 'v19.6' --single-branch https://github.com/davisking/dlib.git dlib/
cd ./dlib
sudo python3 setup.py install --compiler-flags "-mfpu=neon"

Install face_recognition:

sudo pip3 install face_recognition

Revert the swap file size change now that dlib is installed:

sudo nano /etc/dphys-swapfile

< change CONF_SWAPSIZE=1024 to CONF_SWAPSIZE=100 and save / exit nano >

sudo /etc/init.d/dphys-swapfile restart

Download the face recognition code examples:

git clone --single-branch https://github.com/ageitgey/face_recognition.git
cd ./face_recognition/examples
python3 facerec_on_raspberry_pi.py

3.  远程控制

如果想使用远程桌面,有很多工具可选择,比如putty,在IP地址处输入树莓派的ip地址(该IP地址是:在在无线网络管理器处可查询到连接词此路由器的设备,并显示该设备的IP地址),一定要在开启树莓派的ssh使能, raspi-config  /  ingterfaces / ssh

4. opencv 安装

使用 以下指令安装,可能会不稳定,有时候安装不成功。 

sudo pip3 install opencv-python  (sudo pip install opencv-python)

pip3 install opencv-python

 

5. 可能遇到的问题

问题1: 连接网络

若连接公司的宽带网络,可能需要账号授权才能登陆,但是该raspberryPi系统不会弹出登陆页面,最好连接wifi网络,有两种设置方法,分别如下:

1)通过代码

扫描所有无线网络:sudo iwlist wlan0 sacn  

添加无线网络:sudo vim /etc/wpa_supplicant/wpa_supplicant.conf

添加如下代码,只是需要更改id号及相应密码即可

network={
        ssid="ssid_name"
        key_mgmt=WPA-PSK
        psk="password"
}
2)通过命令:

sudo raspi-config  

依次选择网络选项/ WIFI/    然后输入wifi的id 及密码即可

 

问题2:libcblas.so.3: cannot open shared object file: No such file or directory

解决方法:

需要安装 libatlas-base-dev,命令如下:

sudo apt-get install libatlas-base-dev

参考:https://github.com/apache/incubator-mxnet/issues/5290

 

问题3 :opencv安装

pip3 install opencv-python

 

问题4: 安装出错

若使用GIT命令克隆仓库时出现以下错误提示,很可能是网络不稳定导致的,可通过更换无线网络解决。(自己手机开的热点网络变得不稳定,后面在笔记本上用360开了个热点,问题解决)

fatal: The remote end hung up unexpectedly 
fatal: early EOF 
fatal: index-pack failed

问题5 : ImportError: libatlas.so.3: cannot open shared object file: no such file or derectory

解决方法:

需要安装 libatlas-base-dev,命令如下:

sudo apt-get install libatlas-base-dev

问题6:camera is not enabled ,try  running ......

通过sudo raspi-config   / enable   camera    未解决

搜了很多也没找到确切答案,不过可能的愿意是低电压、插错等

问题6: 运行程序 不显示图片及视频

安装imagemagick:   sudo apt-get install imagemagick

原因:因为我在Linux(openSUSE)中使用python,并没有安装pyhon默认的图像浏览器ImageMagick,所以图像浏览器无法启动(参考:https://blog.csdn.net/wzheng92/article/details/79504654       ,http://blog.sina.com.cn/s/blog_5a81b79901015sf9.html

 

这段 import cv2 import face_recognition import numpy as np from PIL import Image, ImageDraw,ImageFont video_capture = cv2.VideoCapture(r'C:/Users/ALIENWARE/123.mp4')#如果输入是(0)为摄像头输入 #现输入为MP4进行识别检测人脸 first_image = face_recognition.load_image_file("1.jpg") first_face_encoding = face_recognition.face_encodings(first_image)[0] Second_image = face_recognition.load_image_file("2.jpg") Second_face_encoding = face_recognition.face_encodings(Second_image)[0] third_image = face_recognition.load_image_file("3.jpg") third_face_encoding = face_recognition.face_encodings(third_image)[0] inside_face_encodings = [first_face_encoding,Second_face_encoding,third_face_encoding] inside_face_names = ['A','B','C'] face_locations = [] face_encodings = [] face_names = [] process_this_frame = True while True: ret, frame = video_capture.read() small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) rgb_small_frame = small_frame[:, :, ::-1] if process_this_frame: face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) face_names = [] for face_encoding in face_encodings: matches = face_recognition.compare_faces(inside_face_encodings, face_encoding) name = '未录入人脸' if True in matches: first_match_index = matches.index(True) name = inside_face_names[first_match_index] face_names.append(name) process_this_frame = not process_this_frame for (top, right, bottom, left), name in zip(face_locations, face_names): top *= 4 right *= 4 bottom *= 4 left *= 4 cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) img_pil = Image.fromarray(frame) draw = ImageDraw.Draw(img_pil) fontStyle = ImageFont.truetype("C:/Windows/Fonts/simsun.ttc", 32, encoding="utf-8") draw.text((left + 6, bottom - 6), name, (0, 200, 0), font=fontStyle) frame = np.asarray(np.array(img_pil)) cv2.imshow('face_out', frame) if cv2.waitKey(1) & 0xFF == ord('q'): #退出需要按下Q键否则内核会崩溃 break video_capture.release() cv2.destroyAllWindows()
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值