Skip to content

Commit 08dfd56

Browse files
authored
Merge pull request #44 from shawncal/shawncal/python3-update
Python3.5 Update, Build speed improvements
2 parents 98dd952 + fd13cc7 commit 08dfd56

17 files changed

+228
-205
lines changed
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
FROM ubuntu:xenial
22

3+
RUN echo "BUILD MODULE: CameraCapture"
4+
35
WORKDIR /app
46

57
RUN apt-get update && \
6-
apt-get install -y --no-install-recommends libcurl4-openssl-dev python-pip libboost-python-dev && \
7-
rm -rf /var/lib/apt/lists/*
8-
8+
apt-get install -y --no-install-recommends \
9+
python3 \
10+
python3-pip \
11+
python3-dev \
12+
libcurl4-openssl-dev \
13+
libboost-python-dev \
14+
libgtk2.0-dev
15+
16+
# Install Python packages
917
COPY /build/amd64-requirements.txt ./
10-
RUN pip install --upgrade pip
11-
RUN pip install --upgrade setuptools && pip install -r amd64-requirements.txt
12-
13-
RUN apt-get update && \
14-
apt-get install -y --no-install-recommends libgtk2.0-dev && \
15-
rm -rf /var/lib/apt/lists/*
18+
RUN pip3 install --upgrade pip
19+
RUN pip3 install --upgrade setuptools
20+
RUN pip3 install -r amd64-requirements.txt
1621

17-
RUN pip install trollius tornado
22+
# Cleanup
23+
RUN rm -rf /var/lib/apt/lists/* \
24+
&& apt-get -y autoremove
1825

1926
ADD /app/ .
2027

2128
# Expose the port
2229
EXPOSE 5012
2330

24-
ENTRYPOINT [ "python", "-u", "./main.py" ]
31+
ENTRYPOINT [ "python3", "-u", "./main.py" ]

modules/CameraCapture/app/CameraCapture.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ def __annotate(self, frame, response):
103103

104104
def __sendFrameForProcessing(self, frame):
105105
headers = {'Content-Type': 'application/octet-stream'}
106-
response = requests.post(self.imageProcessingEndpoint, headers = headers, params = self.imageProcessingParams, data = frame)
106+
try:
107+
response = requests.post(self.imageProcessingEndpoint, headers = headers, params = self.imageProcessingParams, data = frame)
108+
except Exception as e:
109+
print('__sendFrameForProcessing Excpetion -' + str(e))
110+
return "[]"
111+
107112
if self.verbose:
108113
try:
109114
print("Response from external processing service: (" + str(response.status_code) + ") " + json.dumps(response.json()))
@@ -121,7 +126,7 @@ def __enter__(self):
121126
time.sleep(1.0)#needed to load at least one frame into the VideoStream class
122127
#self.capture = cv2.VideoCapture(int(self.videoPath))
123128
else:
124-
#In the case of a video file, we want to analyze all the frames fo the video thus are not using VideoStream class
129+
#In the case of a video file, we want to analyze all the frames of the video thus are not using VideoStream class
125130
self.capture = cv2.VideoCapture(self.videoPath)
126131
return self
127132

@@ -198,7 +203,7 @@ def start(self):
198203
if self.verbose:
199204
print("Time to process frame externally: " + self.__displayTimeDifferenceInMs(time.time(), startProcessingExternally))
200205
startSendingToEdgeHub = time.time()
201-
206+
202207
#forwarding outcome of external processing to the EdgeHub
203208
if response != "[]" and self.sendToHubCallback is not None:
204209
self.sendToHubCallback(response)
Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,47 @@
1-
FROM resin/raspberrypi3-python:2.7
2-
#This image is base on the resin image for building Python apps on Raspberry Pi 3.
1+
FROM balenalib/raspberrypi3
2+
# The balena base image for building apps on Raspberry Pi 3.
33

4-
#Enforces cross-compilation through Quemu
5-
RUN [ "cross-build-start" ]
6-
7-
#update list of packages available
8-
RUN apt-get update && apt-get install -y libboost-python1.55.0
4+
RUN echo "BUILD MODULE: CameraCapture"
95

10-
#Install python packages
11-
COPY /build/arm32v7-requirements.txt ./
12-
RUN pip install --upgrade pip && pip install --upgrade setuptools && pip install -r arm32v7-requirements.txt
6+
# Enforces cross-compilation through Quemu
7+
RUN [ "cross-build-start" ]
138

14-
# Install build modules for openCV
15-
# Based on the work at https://github.com/mohaseeb/raspberrypi3-opencv-docker
16-
RUN sudo apt-get install -y --no-install-recommends \
17-
# to build and install opencv
18-
unzip \
19-
build-essential cmake pkg-config \
20-
# to work with image files
9+
# Update package index and install dependencies
10+
RUN install_packages \
11+
python3 \
12+
python3-pip \
13+
python3-dev \
14+
build-essential \
15+
libopenjp2-7-dev \
16+
zlib1g-dev \
17+
libatlas-base-dev \
18+
wget \
19+
libboost-python1.62.0 \
20+
curl \
21+
libcurl4-openssl-dev
22+
23+
# Required for OpenCV
24+
RUN install_packages \
25+
# Hierarchical Data Format
26+
libhdf5-dev libhdf5-serial-dev \
27+
# for image files
2128
libjpeg-dev libtiff5-dev libjasper-dev libpng-dev \
22-
# to work with video files
29+
# for video files
2330
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
24-
# to display GUI
25-
libgtk2.0-dev pkg-config \
26-
&& sudo rm -rf /var/lib/apt/lists/* \
27-
&& sudo apt-get -y autoremove
31+
# for gui
32+
libqt4-test libqtgui4 libqtwebkit4 libgtk2.0-dev \
33+
# high def image processing
34+
libilmbase-dev libopenexr-dev
2835

29-
RUN OPENCV_VERSION=3.4.2 \
30-
&& WS_DIR=`pwd` \
31-
&& mkdir opencv \
32-
&& cd opencv \
33-
# download OpenCV and opencv_contrib
34-
&& wget -O opencv.zip https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip \
35-
&& unzip opencv.zip \
36-
&& sudo rm -rf opencv.zip \
37-
&& OPENCV_SRC_DIR=`pwd`/opencv-$OPENCV_VERSION \
38-
# build and install without gpu dependency
39-
&& cd $OPENCV_SRC_DIR \
40-
&& mkdir build && cd build \
41-
&& cmake -D CMAKE_BUILD_TYPE=RELEASE \
42-
-D CMAKE_INSTALL_PREFIX=/usr/local \
43-
-D ENABLE_FAST_MATH=1 \
44-
-D CUDA_FAST_MATH=1 \
45-
-D WITH_OPENCL=off -D WITH_OPENCL_SVM=off \
46-
-D WITH_OPENCLAMDFFT=off \
47-
-D WITH_OPENCLAMDBLAS=off \
48-
-D OPENCV_EXTRA_MODULES_PATH=$OPENCV_CONTRIB_MODULES_SRC_DIR \
49-
-D BUILD_opencv_gpu=off \
50-
.. \
51-
&& make \
52-
&& sudo make install \
53-
# cleanup
54-
&& cd $WS_DIR \
55-
&& sudo rm -rf opencv
36+
# Install Python packages
37+
COPY /build/arm32v7-requirements.txt ./
38+
RUN pip3 install --upgrade pip
39+
RUN pip3 install --upgrade setuptools
40+
RUN pip3 install --index-url=https://www.piwheels.org/simple -r arm32v7-requirements.txt
5641

57-
RUN pip install trollius tornado
42+
# Cleanup
43+
RUN rm -rf /var/lib/apt/lists/* \
44+
&& apt-get -y autoremove
5845

5946
RUN [ "cross-build-end" ]
6047

@@ -63,4 +50,4 @@ ADD /app/ .
6350
# Expose the port
6451
EXPOSE 5012
6552

66-
ENTRYPOINT [ "python", "-u", "./main.py" ]
53+
ENTRYPOINT [ "python3", "-u", "./main.py" ]
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
azure-iothub-device-client==1.4.0
1+
azure-iothub-device-client
22
numpy
3-
opencv-python
4-
requests
3+
opencv-contrib-python
4+
requests
5+
trollius
6+
tornado==4.5.3
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
azure-iothub-device-client
12
numpy
3+
opencv-contrib-python
24
requests
3-
azure-iothub-device-client==1.4.0
5+
trollius
6+
tornado==4.5.3

modules/CameraCapture/module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"image": {
55
"repository": "$CONTAINER_REGISTRY_ADDRESS/cameracapture",
66
"tag": {
7-
"version": "0.2.7",
7+
"version": "0.2.8",
88
"platforms": {
99
"amd64": "./amd64.Dockerfile",
1010
"arm32v7": "./arm32v7.Dockerfile",
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
FROM ubuntu:xenial
22

3+
RUN echo "BUILD MODULE: CameraCapture"
4+
35
WORKDIR /app
46

57
RUN apt-get update && \
6-
apt-get install -y --no-install-recommends libcurl4-openssl-dev python-pip libboost-python-dev && \
7-
rm -rf /var/lib/apt/lists/*
8-
8+
apt-get install -y --no-install-recommends \
9+
python3 \
10+
python3-pip \
11+
python3-dev \
12+
libcurl4-openssl-dev \
13+
libboost-python-dev \
14+
libgtk2.0-dev
15+
16+
# Install Python packages
917
COPY /build/amd64-requirements.txt ./
10-
RUN pip install --upgrade pip
11-
RUN pip install --upgrade setuptools && pip install -r amd64-requirements.txt
12-
13-
RUN apt-get update && \
14-
apt-get install -y --no-install-recommends libgtk2.0-dev && \
15-
rm -rf /var/lib/apt/lists/*
18+
RUN pip3 install --upgrade pip
19+
RUN pip3 install --upgrade setuptools
20+
RUN pip3 install -r amd64-requirements.txt
1621

17-
RUN pip install trollius tornado
22+
# Cleanup
23+
RUN rm -rf /var/lib/apt/lists/* \
24+
&& apt-get -y autoremove
1825

1926
ADD /app/ .
2027
ADD /test/ .
@@ -23,4 +30,4 @@ ADD /test/ .
2330
EXPOSE 5012
2431

2532
#Manually run the main.py or test other functions
26-
ENTRYPOINT [ "python", "-u", "./main.py" ]
33+
ENTRYPOINT [ "python3", "-u", "./main.py" ]
Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,47 @@
1-
FROM resin/raspberrypi3-python:2.7
2-
#This image is base on the resin image for building Python apps on Raspberry Pi 3.
1+
FROM balenalib/raspberrypi3
2+
# The balena base image for building apps on Raspberry Pi 3.
33

4-
#Enforces cross-compilation through Quemu
5-
RUN [ "cross-build-start" ]
6-
7-
#update list of packages available
8-
RUN apt-get update && apt-get install -y libboost-python1.55.0
4+
RUN echo "BUILD MODULE: CameraCapture"
95

10-
#Install python packages
11-
COPY /build/arm32v7-requirements.txt ./
12-
RUN pip install --upgrade pip && pip install --upgrade setuptools && pip install -r arm32v7-requirements.txt
6+
# Enforces cross-compilation through Quemu
7+
RUN [ "cross-build-start" ]
138

14-
# Install build modules for openCV
15-
# Based on the work at https://github.com/mohaseeb/raspberrypi3-opencv-docker
16-
RUN sudo apt-get install -y --no-install-recommends \
17-
# to build and install opencv
18-
unzip \
19-
build-essential cmake pkg-config \
20-
# to work with image files
9+
# Update package index and install dependencies
10+
RUN install_packages \
11+
python3 \
12+
python3-pip \
13+
python3-dev \
14+
build-essential \
15+
libopenjp2-7-dev \
16+
zlib1g-dev \
17+
libatlas-base-dev \
18+
wget \
19+
libboost-python1.62.0 \
20+
curl \
21+
libcurl4-openssl-dev
22+
23+
# Required for OpenCV
24+
RUN install_packages \
25+
# Hierarchical Data Format
26+
libhdf5-dev libhdf5-serial-dev \
27+
# for image files
2128
libjpeg-dev libtiff5-dev libjasper-dev libpng-dev \
22-
# to work with video files
29+
# for video files
2330
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
24-
# to display GUI
25-
libgtk2.0-dev pkg-config \
26-
&& sudo rm -rf /var/lib/apt/lists/* \
27-
&& sudo apt-get -y autoremove
31+
# for GUI
32+
libqt4-test libqtgui4 libqtwebkit4 libgtk2.0-dev \
33+
# high def image processing
34+
libilmbase-dev libopenexr-dev
2835

29-
RUN OPENCV_VERSION=3.4.2 \
30-
&& WS_DIR=`pwd` \
31-
&& mkdir opencv \
32-
&& cd opencv \
33-
# download OpenCV and opencv_contrib
34-
&& wget -O opencv.zip https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip \
35-
&& unzip opencv.zip \
36-
&& sudo rm -rf opencv.zip \
37-
&& OPENCV_SRC_DIR=`pwd`/opencv-$OPENCV_VERSION \
38-
# build and install without gpu dependency
39-
&& cd $OPENCV_SRC_DIR \
40-
&& mkdir build && cd build \
41-
&& cmake -D CMAKE_BUILD_TYPE=RELEASE \
42-
-D CMAKE_INSTALL_PREFIX=/usr/local \
43-
-D ENABLE_FAST_MATH=1 \
44-
-D CUDA_FAST_MATH=1 \
45-
-D WITH_OPENCL=off -D WITH_OPENCL_SVM=off \
46-
-D WITH_OPENCLAMDFFT=off \
47-
-D WITH_OPENCLAMDBLAS=off \
48-
-D OPENCV_EXTRA_MODULES_PATH=$OPENCV_CONTRIB_MODULES_SRC_DIR \
49-
-D BUILD_opencv_gpu=off \
50-
.. \
51-
&& make \
52-
&& sudo make install \
53-
# cleanup
54-
&& cd $WS_DIR \
55-
&& sudo rm -rf opencv
36+
# Install Python packages
37+
COPY /build/arm32v7-requirements.txt ./
38+
RUN pip3 install --upgrade pip
39+
RUN pip3 install --upgrade setuptools
40+
RUN pip3 install --index-url=https://www.piwheels.org/simple -r arm32v7-requirements.txt
5641

57-
RUN pip install trollius tornado
42+
# Cleanup
43+
RUN rm -rf /var/lib/apt/lists/* \
44+
&& apt-get -y autoremove
5845

5946
RUN [ "cross-build-end" ]
6047

@@ -64,4 +51,4 @@ ADD /test/ .
6451
# Expose the port
6552
EXPOSE 5012
6653

67-
ENTRYPOINT [ "python", "-u", "./main.py" ]
54+
ENTRYPOINT [ "python3", "-u", "./main.py" ]

modules/ImageClassifierService/amd64.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
FROM tensorflow/tensorflow:latest-py3
22

3+
RUN echo "BUILD MODULE: ImageClassifierService"
4+
35
COPY /build/amd64-requirements.txt amd64-requirements.txt
46

7+
# Install Python packages
58
RUN pip install -r amd64-requirements.txt
69

710
ADD app /app

0 commit comments

Comments
 (0)