后面的话,我们都需要在strnum这个字符串里处理了,简单来说就是从数字的先后位置来指定数字顺序。空格前为第一个数字,空格后是第二个。这里我用了个套娃,先运行分割,再使用stod把字符转换为数字。stod应该来自“string to double”, 我记得还有stoi:”string to int”,之后还有很多,这些转换的功能,还是挺方便的。
#阿里源 deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
还有一些其他的国内源:
#中科大源 deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#163源 deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
#清华源 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
What we need in this deployment is a raspberry pi, a pi camera, if you have a screen for raspberry pi it will be better. We also need an internet connection for modules!
Set up our raspbian in raspberry pi. It is very easy to write an image in your sd card, by using “raspberry pi imager“. This is much more convenient than downloading the image by yourself and write using other software.
if you don’t have a screen or ethernet connection for our raspberry pi, it is necessary to set up a wifi connection before we start up the system. Go to the boot direction in this raspbian SD card, create a file named as “wpa_supplicant.conf“, copy the code below into this .conf file:
Replace Wifi SSID and Wifi password in the code, then you are good to go.
Boot up the raspberry pi and connect the pi camera to it, find the IP address of raspberry pi on your computer. Using ssh to connect Raspberry pi. For the first time startup on pi, the username should be pi, and the password should be raspberry.
SSH on windows has the various options, shell and putty are both great software and easy to setup. On Linux is easier, the command will just be:
ssh 192.168.xx.xx@pi
Now we are ready to move on installing OpenCV! Don’t forget to run these two commands every time!
sudo apt-get update
sudo apt-get upgrade
remove the software we don’t need, but it’s optional:
Then we can setup our camera and expand file system on this command: sudo raspi-config Camera option is in 5Interfacing options, expand file system is in 7Advance options.
We can take a reboot right now by :sudo reboot. After rebooting, we can use the command: df -h to check the system size.
Usually, in the raspbian system, the python2 and python3 is preinstalled. But we need the module pip in our system. Command: wget https://bootstrap.pypa.io/get-pip.py
Then open this py file: sudo python3 get-pip.py
We want to use python3 instead of python2. After this command, pip3 should be a command in the shell.
Finally, it is time to install our OpenCV module! There are two ways to install, we will take an easy way by using pip. We can also use source code to build, but it will take over 2 hours to finish. Using pip will be much faster. Commands are below:
pip install opencv-python
pip install opencv-contrib-python
Haha, if there is no error message show, Opencv is now installed in our raspberry pi! But don’t get excited too soon my brother, let’s using python3 to check again.
Type python3 in console, then type “import cv2“, hit enter. If still no error message, type “cv2.__version__“. When you see your OpenCV version, congratulations! You finally installed your OpenCV successfully!
Follow these steps, we can also install OpenCV on our Linux and Windows computers, they are basically the same.