Suck the cat with code! This paper is participating in[Cat Essay Campaign].
Premise Background:
Take a look at the domestic cat growing increasingly aggressive ing… An old father’s smile…
Young and handsome Kitty Kitty(graph)
The oral vaccine of the neck disappearing surgery(graph)
I took another look at my wallet. The defecator shed the tears of the poor
Shovel excrement officer can not help Shouting “who else!!”
Yes… 2, 3, 4, 5… Waiting for feeding…
Therefore, in order to let the poop master Ben can eat a hot meal, he spent a huge sum of money to buy a “smart pet feeder”, in order to reduce their eating speed, for several days, as expected, immediately effect, beautiful women weight increased X2
(No picture: imagine X2)
Shovel excrement officer can not help Shouting 1 “excrement can endure what can not endure,”!! I was about to kill “a smart pet feeder” with a knife… The idea of $9.9 instead of 999 popped into my head.
Creative content:
Dunden dunden dunden… Deng… The cat Face Recognition Feed is available for $9.90 instead of 999
In theory, by connecting the facial recognition system to the camera and switching on and off the smart pet feeder, each cat can only get new food through the cat face recognition system when the feeder runs out of food, and each cat can get up to two portions of food a day.(Bug: It doesn’t rule out some cats eating new cat food after other cats get it)
In reality, he is just a shod shit officer, Ubuntu is what, python is what do not understand wow, on the Internet only find how to make their own face recognition system, as for how to connect these several kinds of magic tools, do not know wow, wait for the programming masters can achieve it
Production content:
Make your own from the great god the network posts zhuanlan.zhihu.com/p/37083166 face recognition system
Preparations: Camera, Ubuntu system, Python development environment, network environment
\
Yes, it’s that simple. There’s not much to prepare. You can build it on Windows, if you like.
\
Install python dependencies \
For python, you can download Anaconda, a Python integrated development environment that contains a large number of Python dependencies. Next you’ll install some dependencies that aren’t in Anaconda: Face_recognition, OpenaCV, Pymysql, wxpy
\
For Pymysql, you can install:
pip install pymysql -i https://pypi.tuna.tsinghua.edu.cn/simple
Copy the code
Face_recognition and OpenaCV are cumbersome
\
Install OpenCV
\
Install a bunch of cores:
#Remove any previous installations of x264 sudo apt-get remove x264 libx264-dev #We will Install dependencies now sudo apt-get install build-essential checkinstall cmake pkg-config yasmsudo apt-get install git gfortransudo apt-get install Libjpeg8 -dev libjasper-dev libpng12-dev # If you are using Ubuntu 14.04 sudo apt-get install libtiff4-dev # If you are Using Ubuntu 16.04 sudo apt-get install libtiff5-dev sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev Libdc1394-22 -dev sudo apt-get install libxine2-dev libv4l-dev sudo apt-get install libgstreamer0.10-dev Libgstreamer-plugins-base0.10 -dev sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev sudo apt-get install libatlas-base-devsudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev sudo apt-get install libvorbis-dev libxvidcore-dev sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev sudo apt-get install x264 v4l-utils # Optional dependencies sudo apt-get install libprotobuf-dev protobuf-compiler sudo apt-get install libgoogle-glog-dev libgflags-dev sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygenCopy the code
Download the OpencV package:
Git clone https://github.com/opencv/opencv.git CD opencv git checkout 3.3.1 CD..Copy the code
Download the opencv_contrib package:
Git clone https://github.com/opencv/opencv_contrib.git CD opencv_contrib git checkout 3.3.1 CD..Copy the code
Start compiling:
cd opencv mkdir release cd release cmake -DBUILD_TIFF=ON \ -DBUILD_opencv_java=OFF \ -DWITH_CUDA=OFF \ -DWITH_OPENGL=ON \ -DWITH_OPENCL=ON \ -DWITH_IPP=ON \ -DWITH_TBB=ON \ -DWITH_EIGEN=ON \ -DWITH_V4L=ON \ -DWITH_VTK=OFF \ -DBUILD_TESTS=OFF \ -DBUILD_PERF_TESTS=OFF \ -DCMAKE_BUILD_TYPE=RELEASE \ -DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") \ -DPYTHON3_EXECUTABLE=$(which python) \ -DPYTHON3_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ -DPYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \ .. make -j4 make install # not sudo, except for Raspberry Pi #Note: on the Raspberry Pi, consider make -j2 to avoid over-temperature and under-voltage warnings (in general when compiling on Raspberry Pi, not just for OpenCV).Copy the code
At this point, OpencV is compiled in your
/ home / [user_name] / anaconda3 / lib/python3.6 / site - packages /
Create a soft link to your virtual environment:
CD/home / [user_name] / anaconda3 / lib/python3.6 / site - packages/ln -s / home / [user_name] / anaconda3 / lib/python3.6 / site - packages/cv2. Retaining - 36 m - x86_64 - Linux - gnu so cv2. SoCopy the code
To verify this, open ipython:
In [1]: import cv2
In [2]: print(cv2.__version__)
3.3.1-dev
Copy the code
Install face_recognition
This is relatively simple, the official wrote a very detailed document, you can download to see:
\
Media.readthedocs.org/pdf/face-re…
\
To be clear, be careful when reading installation instructions. Before installing FACE_recognition, you will need to install dlib, which is linked to the documentation.
\
Face recognition
\
Next, it’s time to write a short program, but don’t panic, there are ready-made examples of the program, just need to change according to their own needs, it’s ok. The advantage of the Python language is that it is very readable. Almost anyone who can read English can read the code, so this code sample is very easy to read, linked here: \
Github.com/ageitgey/fa…
\
The above notes are more detailed, here I pick a few paragraphs to briefly introduce:
Video_capture = cv2.videocapture (0) ① # Find all the faces and face encodings in the current frame of video Face_locations = face_recognition. Face_locations (Small_frame) ② face_encodings = Face_recognition. Face_encodings (small_frame face_locations) (3)Copy the code
The first line is to turn on the camera and start capturing images; The second line is to find the face image in the picture, and the third line is to extract the features in the face image. What are features? You can think of it simply as a set of rules that a computer has created to recognize faces, and those rules are considered faces. \
Find the face and compare it with the stored face. The operation of comparison is actually computing similarity. First of all, the pre-stored face image is vectorized and stored in numpy.array format. Of course, in order to start the program without repeating the stored image vectorization, you can store the results and read them as you use them.
import os import face_recognition import numpy as np import constants as cons know_face_path = cons.BASE_FACES_PATH model_path = cons.MODEL_PATH time_now = cons.time_str known_faces = [] known_names = [] for index, file_name in enumerate(sorted(os.listdir(know_face_path))): Test_image = face_recognition. Load_image_file (know_face_path + '/' + file_name) model = face_recognition.face_encodings(test_image)[0] np.savetxt(model_path + '/' + time_now + '_' + str(index) + '.model', model)Copy the code
Next, calculate the distance, sort, select the minimum value within the threshold I set, and mark it:
match = face_recognition.compare_faces(known_faces, face_encoding, How dis = = 0.38) face_recognition. Face_distance (known_faces, face_encoding) name = "Unknown" id = np.argmin(dis) if match[id]: name = known_names[id].split('.')[0]Copy the code
Ok, that’s the main part of the code, and all that’s left is some customization.
Shovel excrement officer: have no have no, can’t find other can series whole reduce weight magical production method, kneel beg big guys to lift lift hand ~
conclusion
It’s easy to eat, but it’s also great to have a “cat face recognition feeding device” so that cats can live a healthier life and not be unable to jump a step. Wait for which big guys can have a complete production idea, this shoveling excrement officer is just a whim idea ~