├── .gitignore
├── .vscode
└── settings.json
├── CMakeLists.txt
├── LICENSE
├── README.md
├── application
├── include
│ └── mqtt.h
└── src
│ ├── main.cpp
│ └── mqtt.cpp
├── cmake
├── FindDemoOpenVINO.cmake
├── osdetect.cmake
└── pahomqtt.cmake
├── docs
└── images
│ ├── arch1.png
│ ├── arch2.png
│ ├── arch3.png
│ └── parking-lot-counter.png
├── resources
├── config.json
└── diagrams.txt
└── setup.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | .vagrant/
2 | Vagrantfile
3 | build/
4 | *.mp4
5 | json
6 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "files.associations": {
3 | "thread": "cpp"
4 | }
5 | }
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2018 Intel Corporation.
2 | #
3 | # Permission is hereby granted, free of charge, to any person obtaining
4 | # a copy of this software and associated documentation files (the
5 | # "Software"), to deal in the Software without restriction, including
6 | # without limitation the rights to use, copy, modify, merge, publish,
7 | # distribute, sublicense, and/or sell copies of the Software, and to
8 | # permit persons to whom the Software is furnished to do so, subject to
9 | # the following conditions:
10 | #
11 | # The above copyright notice and this permission notice shall be
12 | # included in all copies or substantial portions of the Software.
13 | #
14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
22 | cmake_minimum_required(VERSION 2.8.11)
23 | project(FAC)
24 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
25 |
26 | # Fancy colorized output messages
27 | string(ASCII 27 Esc)
28 | set(CR "${Esc}[m")
29 | set(Red "${Esc}[1;31m")
30 | set(Green "${Esc}[1;32m")
31 | set(Blue "${Esc}[1;34m")
32 |
33 | # Allow users to manually set OpenCV path if desired
34 | set(OpenCV_DIR CACHE PATH "Path to Intel OpenCV library")
35 |
36 | message(STATUS "${Blue}Intel Shopper Gaze Monitor${CR}")
37 |
38 | # Check OS
39 | message(STATUS "${Blue}Checking OS version...${CR}")
40 |
41 | set(REQUIRED_OS_ID "Ubuntu")
42 | set(REQUIRED_OS_VERSION "18.04")
43 | include(osdetect)
44 |
45 | # Check for Intel OpenVINO
46 | message(STATUS "${Blue}Checking prerequisites...${CR}")
47 |
48 | find_package(DemoOpenVINO)
49 | if(NOT OpenCV_FOUND)
50 | message(FATAL_ERROR "${Red}Intel OpenVINO was not found!\n${Blue}Have you sourced the ${Green}setupvars.sh${Blue} script provided by the Intel OpenVINO?${CR}")
51 | endif( )
52 |
53 | include_directories(${OpenCV_INCLUDE_DIRS})
54 | include_directories(json/single_include)
55 | include_directories(application/include)
56 |
57 | # Install paho MQTT dependency
58 | include(pahomqtt)
59 |
60 | # Application executables
61 | set(MONITOR monitor)
62 | set(DSOURCES application/src/main.cpp application/src/mqtt.cpp)
63 | add_executable(${MONITOR} ${DSOURCES})
64 | add_dependencies(${MONITOR} pahomqtt)
65 | set_target_properties(${MONITOR} ${TRAINER} PROPERTIES COMPILE_FLAGS "-pthread -std=c++11")
66 | target_link_libraries (${MONITOR} ${OpenCV_LIBS} pthread paho-mqtt3cs)
67 |
68 | # Install
69 | install(TARGETS ${MONITOR} DESTINATION bin)
70 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2021, Intel Corporation
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | 3. Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DISCONTINUATION OF PROJECT #
2 | This project will no longer be maintained by Intel.
3 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.
4 | Intel no longer accepts patches to this project.
5 | # Parking Lot Counter
6 |
7 | | Details | |
8 | |-----------------------|---------------|
9 | | Target OS: | Ubuntu\* 18.04 LTS |
10 | | Programming Language: | C++ |
11 | | Time to Complete: | 45 min |
12 |
13 | 
14 |
15 | ## Introduction
16 |
17 | This reference implementations is designed for a parking space area with mounted camera which monitors available parking space by tracking the count of the vehicles entering and leaving the parking space area.
18 |
19 | ## Requirements
20 |
21 | ### Hardware
22 | * 6th to 8th Generation Intel® Core™ processors with Intel® Iris® Pro graphics or Intel® HD Graphics
23 |
24 | ### Software
25 | * [Ubuntu\* 18.04 LTS](http://releases.ubuntu.com/18.04/)
26 | **Note**: We recommend using a 4.14+ kernel to use this software. Run the following command to determine your kernel version:
27 | ```
28 | uname -a
29 | ```
30 |
31 | * OpenCL™ Runtime Package
32 | * Intel® Distribution of OpenVINO™ toolkit 2020 R3 Release
33 |
34 | ## How it Works
35 |
36 | The application uses a video source, such as a camera, to grab frames, and then uses a Deep Neural Network (DNNs) to process the data. The network detects vehicles in the frame and then if successful it tracks the vehicles leaving or entering the parking area and adjusts the count of the vehicles in the parking area for providing the information about the available parking spaces.
37 |
38 | The data can then optionally be sent to a MQTT machine to machine messaging server, as part of a parking space data analytics system.
39 |
40 | 
41 |
42 | The program creates three threads for concurrency:
43 |
44 | - Main thread that performs the video I/O
45 | - Worker thread that processes video frames using DNNs
46 | - Worker thread that publishes any MQTT messages
47 |
48 |
49 | ## Setup
50 | ### Get the code
51 | Clone the reference implementation:
52 | ```
53 | sudo apt-get update && sudo apt-get install git
54 | git clone https://github.com/intel-iot-devkit/parking-lot-counter-cpp.git
55 | ```
56 |
57 | ### Install OpenVINO
58 | Refer to https://software.intel.com/en-us/articles/OpenVINO-Install-Linux for more information about how to install and setup the Intel® Distribution of OpenVINO™ toolkit.
59 |
60 | You will need the OpenCL™ Runtime package if you plan to run inference on the GPU as shown by the
61 | instructions below. It is not mandatory for CPU inference.
62 |
63 | ## Other dependencies
64 | **Mosquitto**
65 |
66 | Mosquitto is an open source message broker that implements the MQTT protocol. The MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model.
67 |
68 | ## Which model to use
69 |
70 | This application uses the [pedestrian-and-vehicle-detector-adas-0001](https://docs.openvinotoolkit.org/2020.3/_models_intel_pedestrian_and_vehicle_detector_adas_0001_description_pedestrian_and_vehicle_detector_adas_0001.html) Intel® model, that can be downloaded using the **model downloader**. The **model downloader** downloads the __.xml__ and __.bin__ files that will be used by the application.
71 |
72 | To download the models and install the dependencies of the application, run the below command in the `parking-lot-counter-cpp` directory:
73 | ```
74 | ./setup.sh
75 | ```
76 |
77 | ### The Config File
78 |
79 | The _resources/config.json_ contains the path of video that will be used by the application as input.
80 |
81 | For example:
82 | ```
83 | {
84 | "inputs": [
85 | {
86 | "video":"path_to_video/video1.mp4"
87 | }
88 | ]
89 | }
90 | ```
91 |
92 | The `path/to/video` is the path to an input video file.
93 |
94 | ### Which Input Video to use
95 |
96 | The application works with any input video. Sample videos are provided [here](https://github.com/intel-iot-devkit/sample-videos/).
97 |
98 | For first-use, we recommend using the [car-detection.mp4](https://github.com/intel-iot-devkit/sample-videos/blob/master/car-detection.mp4) video.
99 | For example:
100 | ```
101 | {
102 | "inputs": [
103 | {
104 | "video":"sample-videos/car-detection.mp4"
105 | }
106 | ]
107 | }
108 | ```
109 | If the user wants to use any other video, it can be used by providing the path in the config.json file.
110 |
111 | ### Using the Camera Stream instead of video
112 |
113 | Replace `path/to/video` with the camera ID in the config.json file, where the ID is taken from the video device (the number **X** in /dev/video**X**).
114 |
115 | On Ubuntu, to list all available video devices use the following command:
116 |
117 | ```
118 | ls /dev/video*
119 | ```
120 |
121 | For example, if the output of above command is __/dev/video0__, then config.json would be:
122 |
123 | ```
124 | {
125 | "inputs": [
126 | {
127 | "video":"0"
128 | }
129 | ]
130 | }
131 | ```
132 |
133 | ### Setup the Environment
134 |
135 | Configure the environment to use the Intel® Distribution of OpenVINO™ toolkit by exporting environment variables:
136 |
137 | ```
138 | source /opt/intel/openvino/bin/setupvars.sh
139 | ```
140 |
141 | __Note__: This command needs to be executed only once in the terminal where the application will be executed. If the terminal is closed, the command needs to be executed again.
142 |
143 | ### Build the application
144 |
145 | To build, go to the `parking-lot-counter-cpp` and run the following commands:
146 |
147 | ```
148 | mkdir -p build && cd build
149 | cmake ..
150 | make
151 | ```
152 |
153 | ## Run the application
154 |
155 | To see a list of the various options:
156 | ```
157 | ./monitor -help
158 | ```
159 |
160 | ### Run on the CPU
161 | To run the application with the required models using webcam, execute the below command:
162 | ```
163 | ./monitor -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP32/pedestrian-and-vehicle-detector-adas-0001.bin -c=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP32/pedestrian-and-vehicle-detector-adas-0001.xml
164 | ```
165 |
166 | To control the position of the parking entrance/exit use the `-entrance, -e` command line flag. For example:
167 | ```
168 | ./monitor -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP32/pedestrian-and-vehicle-detector-adas-0001.bin -c=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP32/pedestrian-and-vehicle-detector-adas-0001.xml -e="b"
169 | ```
170 |
171 | The `-entrance` flag controls which part of the video stream frame has to be used for counting the cars entering or exiting the parking lot:
172 | * `"b"`: bottom
173 | * `"l"`: left
174 | * `"r"`: right
175 | * `"t"`: top
176 |
177 | To control the car detection DNN confidence level, use the `-carconf, -cc` flag. For example, `-carconf=0.6` will track all cars whose DNN detection confidence level is higher than `60%`.
178 |
179 | The calculations made to track the movement of vehicles using centroids have two parameters that can be set via command line flags. `--max_distance` set the maximum distance in pixels between two related centroids. In other words, how big of a distance of movement between frames show be allowed before assuming that the object is a different vehicle. `--max_frames_gone` is the maximum number of frames to track a centroid which doesn't change, possibly due to being a parked vehicle.
180 |
181 | ### Run on the Integrated GPU
182 |
183 | This application can take advantage of the hardware acceleration in the Intel® Distribution of OpenVINO™ toolkit by using the `-b` and `-t` parameters.
184 |
185 | - To run the application on the integrated Intel® GPU in 32-bit mode, use the below command:
186 | ```
187 | ./monitor -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP32/pedestrian-and-vehicle-detector-adas-0001.bin -c=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP32/pedestrian-and-vehicle-detector-adas-0001.xml -b=2 -t=1
188 | ```
189 | **FP32**: FP32 is single-precision floating-point arithmetic uses 32 bits to represent numbers. 8 bits for the magnitude and 23 bits for the precision. For more information, [click here](https://en.wikipedia.org/wiki/Single-precision_floating-point_format)
190 |
191 | - To run the application on the integrated Intel® GPU in 16-bit mode, use the below command:
192 | ```
193 | ./monitor -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP16/pedestrian-and-vehicle-detector-adas-0001.bin -c=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP16/pedestrian-and-vehicle-detector-adas-0001.xml -b=2 -t=2
194 | ```
195 | **FP16**: FP16 is half-precision floating-point arithmetic uses 16 bits. 5 bits for the magnitude and 10 bits for the precision. For more information, [click here](https://en.wikipedia.org/wiki/Half-precision_floating-point_format)
196 |
197 | ### Run on the Intel® Neural Compute Stick
198 |
199 | To run the application using the Intel® Neural Compute Stick, use the below command:
200 | ```
201 | ./monitor -m=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP16/pedestrian-and-vehicle-detector-adas-0001.bin -c=/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/intel/pedestrian-and-vehicle-detector-adas-0001/FP16/pedestrian-and-vehicle-detector-adas-0001.xml -b=2 -t=3
202 | ```
203 |
204 | ### Machine to Machine Messaging with MQTT
205 |
206 | #### Install Mosquitto Broker
207 | ```
208 | sudo apt-get update
209 | sudo apt-get install mosquitto mosquitto-clients
210 | ```
211 |
212 | If you wish to use a MQTT server to publish data, you should set the following environment variables before running the program:
213 | ```
214 | export MQTT_SERVER=localhost:1883
215 | export MQTT_CLIENT_ID=cvservice
216 | ```
217 |
218 | Change the `MQTT_SERVER` to a value that matches the MQTT server you are connecting to.
219 |
220 | You should change the `MQTT_CLIENT_ID` to a unique value for each monitoring station, so you can track the data for individual locations. For example:
221 | ```
222 | export MQTT_CLIENT_ID=parkinglot1337
223 | ```
224 |
225 | If you want to monitor the MQTT messages sent to your local server, and you have the mosquitto client utilities installed, you can run the following command on a new terminal while the application is running:
226 | ```
227 | mosquitto_sub -t 'parking/counter'
228 | ```
229 |
230 |
--------------------------------------------------------------------------------
/application/include/mqtt.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Intel Corporation.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining
5 | * a copy of this software and associated documentation files (the
6 | * "Software"), to deal in the Software without restriction, including
7 | * without limitation the rights to use, copy, modify, merge, publish,
8 | * distribute, sublicense, and/or sell copies of the Software, and to
9 | * permit persons to whom the Software is furnished to do so, subject to
10 | * the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be
13 | * included in all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 |
24 | #ifndef MQTT_H_INCLUDED
25 | #define MQTT_H_INCLUDED
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | extern "C" {
36 | #include "MQTTClient.h"
37 | #include "MQTTClientPersistence.h"
38 | }
39 |
40 | #define QOS 1
41 | #define TIMEOUT 1000L
42 |
43 | struct mqtt_service_config
44 | {
45 | std::string server;
46 | std::string client_id;
47 | std::string topic;
48 | std::string username;
49 | std::string password;
50 | std::string cert;
51 | std::string cert_key;
52 | std::string ca_root;
53 | };
54 |
55 | std::string std_getenv(const std::string &name);
56 | std::pair get_mqtt_config();
57 | int mqtt_start(MQTTClient_messageArrived* msgrcv);
58 | void mqtt_close();
59 | void mqtt_connect();
60 | void mqtt_disconnect();
61 | int mqtt_publish(std::string const &topic, std::string const &message);
62 | void mqtt_subscribe(std::string const &topic);
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/application/src/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Intel Corporation.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining
5 | * a copy of this software and associated documentation files (the
6 | * "Software"), to deal in the Software without restriction, including
7 | * without limitation the rights to use, copy, modify, merge, publish,
8 | * distribute, sublicense, and/or sell copies of the Software, and to
9 | * permit persons to whom the Software is furnished to do so, subject to
10 | * the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be
13 | * included in all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include