raspberry + openCV 前置作業
http://yehnan.blogspot.tw/2015/12/raspberry-piraspbianopencv.html
直接安裝OpenCV的lib
sudo apt-get install libopencv-dev python-opencv
很棒的raspberry + openCV + camera 教學
https://www.raspberrypi.com.tw/tag/opencv/
https://www.slideshare.net/raspberrypi-tw/raspberry-pi-camera-python-opencv-day1
https://projects.raspberrypi.org/en/projects/getting-started-with-picamera
用Raspberry Pi學GPIO - 自己做遊戲機
http://www.slideshare.net/raspberrypi-tw/gpio-gameconsolestarterkit
PPT download
http://goo.gl/0nj2JB
sample code
http://goo.gl/BrPPP8
#開機就執行
#● 一次性的執行 , 可以放在 /etc/rc.local 裡
$ sudo nano /etc/rc.local
sudo python /home/pi/gpio-game-console/11_3-joystick_mapping_keyboard/joystick_mapping_keyboard.py &
#● 以服務的方式執行 , 需寫 systemd 設定檔
#新增 systemd 設定檔
$ sudo nano /lib/systemd/system/my_systemd.service
[Unit]
Description=Add a New Systemd
[Service]
ExecStart=/home/pi/my_systemd.sh
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
#● 有畫面的程式前景執行 , 用 LXDE 的 autostart
$ nano ~/.config/lxsession/LXDE-pi/autostart
@lxterminal -e /home/pi/gpio-game-console/11_3-joystick_mapping_keyboard/housenka.sh
#Q1 how to control PC
#http://blog.itist.tw/2016/03/clean-installation-and-setup-on-raspbian-jessie.html
#自動校時 (另一種方式就是用Server丟一個目前時間到Client,然後Clinet再照這個時間去設定)
sudo timedatectl set-ntp yes
sudo date 110121432016 #MMDDhhmmYYYY
# http://raspberrypihq.com/how-to-share-a-folder-with-a-windows-computer-from-a-raspberry-pi/
sudo apt-get -y update
sudo apt-get -y upgrade #更新的部分,不一定要進行如果你覺得你的系統穩定的話通常很多人是不會將系統進行更新免得產生額外問題,所以更新部分視情況決定就可以了。
sudo rpi-update
#xrdp port 3389
sudo apt-get install -y xrdp samba samba-common-bin
sudo shutdown now
sudo reboot
netstat -tlunp | grep mbd
sudo raspi-config
sudo chmod -R 777 Test
#---samba-------------------------------------------------------
sudo nano /etc/samba/smb.conf
workgroup = WORKGROUP
wins support = yes
netbios=raspberryk
dos charset = cp950
display charset=utf8
security=user
passdb backend=tdbsam
unix password sync = yes
passwd program = /usr/bin/passwd %u
pam password change = yes
[pi]
comment=Raspberry Pi
path=/home/pi
browseable=no
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=yes
[PiShare]
comment=Raspberry Pi Share
path=/home/pi/share
browseable=no
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=yes #public file or not
[ICU]
comment=Raspberry Pi ICU
path=/home/pi/icu
browseable=Yes
writeable=Yes
only guest=Yes
create mask=0777
directory mask=0777
public=yes #public file or not
sudo smbpasswd -a pi #add user pi
sudo service samba restart
sudo /etc/init.d/samba restart
testparm #查閱 smb.conf 的語法設定正確性
#---中文-------------------------------------------------------
# http://www.pcdiy.com.tw/detail/3773
#1.
sudo raspi-config
#Internationalisation Options -->Change Locale -->zh_TW.UTF-8
#2.
sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy
#3.
sudo apt-get install scim-chewing
#---OpenCV No need-------------------------------------------------------
# http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/
#We then need to install some developer tools, including CMake, which helps us configure the OpenCV build process:
sudo apt-get install build-essential cmake pkg-config
#Next, we need to install some image I/O packages that allow us to load various image file formats from disk. Examples of such file formats include JPEG, PNG, TIFF, etc.:
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
#Just as we need image I/O packages, we also need video I/O packages. These libraries allow us to read various video file formats from disk as well as work directly with video streams:
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
#The OpenCV library comes with a sub-module named highgui which is used to display images to our screen and build basic GUIs. In order to compile the highgui module, we need to install the GTK development library:
sudo apt-get install libgtk2.0-dev
#Many operations inside of OpenCV (namely matrix operations) can be optimized further by installing a few extra dependencies:
sudo apt-get install libatlas-base-dev gfortran
#Lastly, let’s install both the Python 2.7 and Python 3 header files so we can compile OpenCV with Python bindings:
sudo apt-get install python2.7-dev python3-dev
#Now that we have our dependencies installed, let’s grab the 3.1.0 archive of OpenCV from the official OpenCV repository. (Note: As future versions of openCV are released, you can replace 3.1.0 with the latest version number):
cd ~
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
unzip opencv.zip
#We’ll want the full install of OpenCV 3 (to have access to features such as SIFT and SURF, for instance), so we also need to grab the opencv_contrib repository as well:
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
unzip opencv_contrib.zip
#Before we can start compiling OpenCV on our Raspberry Pi 3, we first need to install pip , a Python package manager:
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
#So, given that, what’s the point of using virtualenv and virtualenvwrapper ?
#-----omnitty 批量管理多台linux介面-----------------------------------------------------
#require tool.
apt-get install libncurses5-dev
#http://omnitty.sourceforge.net/
# rote-0.2.8.tar.gz
./configure
make
make install
# omnitty-0.3.0.tar.gz
./configure
make
make install
#if error, try this.
#在/etc/ld.so.conf.d/下寫入一個omnitty.conf的檔案,內容寫入/usr/local/lib即可,之後重新執行/sbin/ldconfig
sudo echo /usr/local/lib > /etc/ld.so.conf.d/omnitty.conf
sudo ./sbin/ldconfig
#Added -lncurses and -ltinfo in Makefile of omnitty
#eg.
$(CC) $(CFLAGS) -o omnitty $(objects) $(LDFLAGS) $(LIBS) -lncurses -ltinfo
#-----Pi camera.py 這個似乎沒辦法透過Xming顯示(因為他是透過硬體?)-----------------------------------------------------
# https://www.raspberrypi.org/learning/getting-started-with-picamera/worksheet/
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.rotation = 180
camera.start_preview()
sleep(10)
camera.stop_preview()
#-----Python camera.py 這個似乎可以透過Xming顯示 (因為他是透過軟體?) -----------------------------------------------------
不過很奇怪,有時候會無法開啟camera 會顯示 "error: (-215) size.width>0 && size.height>0 in function imshow"的錯誤訊息。
解決方法,重新載入驅動
sudo modprobe bcm2835-v4l2
其他指令如下
v4l2-ctl --list-devices
v4l2-ctl --list-formats
v4l2-ctl -L
#參考自 https://www.slideshare.net/raspberrypi-tw/raspberry-pi-camera-python-opencv-day1
import cv2, time
# reference https://gist.github.com/tedmiston/6060034
cam = cv2.VideoCapture(0)#(0)
cam.set(3,800) #reference https://stackoverflow.com/questions/11420748/setting-camera-parameters-in-opencv-python
cam.set(4,600)
while True:
ret_val, img = cam.read()
if mirror:
img = cv2.flip(img, -1)
img = cv2.flip(img, -1)
cv2.imshow("webcam", img)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
#-----RPi-Cam-Web-Interface-----------------------------------------------------
#https://elinux.org/RPi-Cam-Web-Interface#Basic_Installation
sudo apt-get update
sudo apt-get dist-upgrade
sudo rpi-update #Not recommand
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
./install.sh
sudo chmod 755 /etc/rc.local
sudo reboot
./RPi_Cam_Web_Interface_Installer.sh
#-----模擬器-----------------------------------------------------
http://mstar.pixnet.net/blog/post/21804241-linux-%E4%B8%8B%E7%9A%84%E9%81%8A%E6%88%B2%E6%A9%9F%E6%A8%A1%E6%93%AC%E5%99%A8
#-----install utility-----------------------------------------------------
#rpm
sudo apt-get install alien
#7zip
sudo apt-get install p7zip
#unzip
7zr e file.zip
#player
sudo apt-get install smplayer
sudo apt-get install Rhythmbox
#Ubuntu : AVI, RMVB, MPEG, MP3 一次解決
#http://blog.xuite.net/chingwei/blog/27809648-%E3%80%90%E7%B3%BB%E7%B5%B1%E3%80%91Ubuntu+%3A+AVI,+RMVB,+MPEG,+MP3+%E4%B8%80%E6%AC%A1%E8%A7%A3%E6%B1%BA
sudo apt-get install gstreamer0.10-plugins-uglygstreamer0.10-plugins-bad gstreamer0.10-ffmpeg
#-----disable Pi camera LED-----------------------------------------------------
https://www.raspberrypi-spy.co.uk/2013/05/how-to-disable-the-red-led-on-the-pi-camera-module/
sudo nano /boot/config.txt
disable_camera_led=1
#-----install python module-----------------------------------------------------
pip3 install --upgrade pip
sudo pip3 install beautifulsoup4 html5lib pandas h5py keras numpy
pip install --upgrade tensorflow
#For pandas compile
sudo apt-get install gcc-arm-none-eabi
#-----install xming-----------------------------------------------------
sudo apt-get install -y lxde lightdm xinit
http://blog.jangmt.com/2009/11/xming.html
修改/etc/gdm/custom.conf,讓root可以使用
AllowRoot=true
#-----putty cmd-----------------------------------------------------
start putty -ssh yourIP -X -l username -pw userpassword
The -X option turns on X11 forwarding in SSH, and -x turns it off. These options are only meaningful if you are using SSH.
#-----install tensorflow-----------------------------------------------------
pip install --upgrade tensorflow
or
#https://www.wandianshenme.com/play/howto-install-tensorflow-in-raspberry-pi-2/
wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.1.0/tensorflow-1.1.0-cp27-none-linux_armv7l.whl
sudo pip install tensorflow-1.1.0-cp27-none-linux_armv7l.whl
h
#-----proxy settings cmd-----------------------------------------------------
export http_proxy=http://ip:8080
export https_proxy=https://ip:8080
putty cmd: http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter3.html#3.7.3
cd /etc/apt/apt.conf.d
sudo nano 10proxy
Acquire::http::Proxy "http://ip:8080";
http://www.instructables.com/id/Adding-local-internet-proxy-settings-to-Raspberry-/
#-----Clean install all-----------------------------------------------------
sudo apt-get install -y alien p7zip xrdp samba samba-common-bin ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy scim-chewing lxde lightdm xinit python-opencv python-pip x11vnc
picamera doc
http://picamera.readthedocs.io/en/release-1.13/recipes1.html
#-----Clean script-----------------------------------------------------
sudo chmod +x /etc/rc.local #auto run
#-----auto run-----------------------------------------------------
/etc/rc.local # useless
#https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/
sudo nano /etc/init.d/myPiAutoRun.sh #OK
#!/bin/bash
### BEGIN INIT INFO
# Provides: myPiAutoRun.sh
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
if [ -f "/home/pi/python/piCam/Pi_Camera_Photo_telegram.py"];then
sudo /usr/bin/python3 /home/pi/python/piCam/Pi_Camera_Photo_telegram.py &
fi
exit 0
sudo chmod +x myPiAutoRun.sh
sudo update-rc.d myPiAutoRun.sh defaults
grep -rnw "/var/log/daemon.log" -e "myPiAutoRun" #check log
sudo nano /lib/systemd/system/myPiAutoRun.service #not yet
[Unit]
Description=myPiAutoRun
After=multi-user.target
Requires=network-online.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/python/piCam/Pi_Camera_Photo_telegram.py > /home/pi/python/piCam/Pi_Camera_Photo_telegram.log 2>&1
#Restart=always
[Install]
WantedBy=multi-user.target
sudo chmod 644 /lib/systemd/system/myPiAutoRun.service
sudo systemctl enable myPiAutoRun.service
sudo systemctl start myPiAutoRun.service
sudo systemctl status myPiAutoRun
sudo systemctl daemon-reload
sudo reboot
systemctl status myPiAutoRun.service
journalctl -xn
#cmd
sudo reboot
#------localename-------------------------------
#https://github.com/spyder-ide/spyder/issues/4131
error message ValueError, 'unknown locale: %s' % localename
The problelm is solved. I installed the zh_TW.utf-8
with either "sudo locale-gen zh_TW.UTF-8" , or
"sudo dpkg-reconfigure locales" if the former does not work.
#---wlan cmd--------
sudo ifconfig wlan0 up
sudo iwlist wlan0 scan | grep ESSID
sudo iwconfig wlan0 essid ap_ssid key ap_key
sudo gedit /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="AP_SSID"
key_mgmt=WPA-PSK
psk="AP_Key"
}
sudo /etc/init.d/networking restart
sudo iw dev
sudo ip link set wlan0 up
sudo iw wlan0 scan
sudo wpa_passphrase blackMOREOps >> /etc/wpa_supplicant.conf
sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf
sudo iw wlan0 link
sudo dhclient wlan0
sudo ping 8.8.8.8
sudo iwconfig wlan0 txpower auto #change wlan0 power
#---ADSL pppoe cmd--------
sudo apt-get -y install pppoeconf
#---wlan auto connection--------
#https://weworkweplay.com/play/automatically-connect-a-raspberry-pi-to-a-wifi-network/
sudo nano /etc/network/interfaces
auto wlan0
auto eth0
sudo nano wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp