This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrun
executable file
·114 lines (95 loc) · 4.27 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# This script runs both Python scripts when a new file is created via lsyncd
# Note that 'moved_to' is used due to the way rsync works
DIR="$HOME/3DPrintSaviour/output" #path to your image folder
PRINTCTRL="$HOME/3DPrintSaviour/printcontrol.py" #path to printcontrol.py
GETSCORE="$HOME/3DPrintSaviour/get_score.py" #path to get_score.py
usage() { echo -e "$0 usage:\n\tNo flag provided - Runs default with logging, but no debugging." && grep "[[:space:]].)\ #" $0 | sed 's/#//' | sed -r 's/([a-z])\)/-\1/'; exit 0; }
echo "3D Print Saviour running..."
while getopts "dih" arg; do
case $arg in
d) # Debug Mode - Logs output to logfile, does not run print control.
echo -e "DEBUG MODE. Logging Score output to logfile in image directory\nPrint Control disabled"
inotifywait -m -r -e moved_to --format '%w%f' "$DIR" 2> /dev/null | while read f
do
RES_DIR=${f%/*}
$GETSCORE "$f" >> "$RES_DIR/output.log"
done
;;
i) # Install - Installs dependencies, including OpenCV 3, scikit-image, numpy, scipy and OctoClient.
echo -e "Installing dependencies, please note this will be a long process\nThis will NOT set up a virtualenv for OpenCV, follow this guide instead if you wish to use virtualenvs: https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/"
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install -y build-essential cmake pkg-config
sudo apt-get install -y libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install -y libxvidcore-dev libx264-dev
sudo apt-get install -y libgtk2.0-dev libgtk-3-dev
sudo apt-get install -y libatlas-base-dev gfortran
sudo apt-get install -y python2.7-dev python3-dev
sudo apt-get install -y inotify-tools
mkdir ./snapshots
echo "Now downloading weights for detection model"
wget --quiet -O ml_api/model/model.weights $(cat ml_api/model/model.weights.url | tr -d '\r')
# Download and unzip opencv 3.4.6 and opencv_contrib
#echo "Installing OpenCV 3.4.6"
#cd ~
#wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.6.zip
#unzip opencv.zip
#wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.6.zip
#unzip opencv_contrib.zip
# Install pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo python3 get-pip.py
pip3 install numpy
#cd ~/opencv-3.4.6/
#mkdir build
#cd build
#cmake -D CMAKE_BUILD_TYPE=RELEASE \
# -D CMAKE_INSTALL_PREFIX=/usr/local \
# -D INSTALL_PYTHON_EXAMPLES=ON \
# -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.6/modules \
# -D BUILD_EXAMPLES=ON ..
# Increase swapsize to allow quad-core compilation
#sudo sed -i -e 's/CONF_SWPASIZE\=100/CONF_SWAPSIZE\=1024/g' /etc/dphys-swapfile
#sudo /etc/init.d/dphys-swapfile stop
#sudo /etc/init.d/dphys-swapfile start
# Compile OpenCV
#make -j4
# Install OpenCV
#sudo make install
#sudo ldconfig
# Increase swapsize to allow quad-core compilation
#sudo sed -i -e 's/CONF_SWPASIZE\=1024/CONF_SWAPSIZE\=100/g' /etc/dphys-swapfile
#sudo /etc/init.d/dphys-swapfile stop
#sudo /etc/init.d/dphys-swapfile start
#cd /usr/local/lib/python3.6/site-packages/
#sudo mv cv2.cpython-36m-arm-linux-gnueabihf.so cv2.so
#cd ~/.virtualenvs/cv/lib/python3.6/site-packages/
#ln -s /usr/local/lib/python3.6/site-packages/cv2.so cv2.so
#if [ $( python3 -c "exec(\"import cv2\nprint(cv2.__version__)\")" ) == "3.4.6" ];
#then echo "OpenCV 3.4.6 installed succesfully!";
#else echo "OpenCV 3.4.6 did not install correctly, check the output above.";
#fi
echo "Now installing additional dependencies..."
pip3 install scipy
pip3 install scikit-image
git clone https://github.com/hroncok/octoclient.git
cd octoclient
sudo python3 setup.py install
echo "Setup complete!"
;;
h) # Help - Displays help.
usage
exit 0
;;
esac
done
if (( $OPTIND == 1 )); then
inotifywait -m -r -e moved_to --format '%w%f' "$DIR" 2> /dev/null | while read f #change 'created' to 'moved_to' for testing
do
RES_DIR=${f%/*}
python3 $PRINTCTRL `python3 $GETSCORE "$f" | tee -a "$RES_DIR/output.log"`
done
fi
#ctrl+z, bg, disown