{"id":21802447,"url":"https://github.com/qengineering/traffic-counter-rock5c","last_synced_at":"2026-02-05T09:35:22.791Z","repository":{"id":263976020,"uuid":"891970948","full_name":"Qengineering/Traffic-Counter-Rock5C","owner":"Qengineering","description":"A fully functional traffic counter on a bare RK3588 with MQTT and remote live viewer","archived":false,"fork":false,"pushed_at":"2024-11-23T10:46:39.000Z","size":33588,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-25T02:08:51.257Z","etag":null,"topics":["aarch64","bytetracker","cpp","deep-learning","npu","rk3566","rk3568","rk3588","rock5c","traffic-counter","traffic-counting"],"latest_commit_sha":null,"homepage":"https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Qengineering.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-21T09:34:59.000Z","updated_at":"2025-04-01T03:06:01.000Z","dependencies_parsed_at":"2025-07-24T22:35:49.078Z","dependency_job_id":"e7dd44d5-dcb5-4b8b-8f5c-2c0b601001ba","html_url":"https://github.com/Qengineering/Traffic-Counter-Rock5C","commit_stats":null,"previous_names":["qengineering/traffic-counter-rock5c"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Qengineering/Traffic-Counter-Rock5C","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2FTraffic-Counter-Rock5C","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2FTraffic-Counter-Rock5C/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2FTraffic-Counter-Rock5C/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2FTraffic-Counter-Rock5C/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qengineering","download_url":"https://codeload.github.com/Qengineering/Traffic-Counter-Rock5C/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qengineering%2FTraffic-Counter-Rock5C/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29118476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T05:31:32.482Z","status":"ssl_error","status_checked_at":"2026-02-05T05:31:29.075Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aarch64","bytetracker","cpp","deep-learning","npu","rk3566","rk3568","rk3588","rock5c","traffic-counter","traffic-counting"],"created_at":"2024-11-27T11:28:42.136Z","updated_at":"2026-02-05T09:35:22.760Z","avatar_url":"https://github.com/Qengineering.png","language":"C++","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=CPZTM5BB3FCYL"],"categories":[],"sub_categories":[],"readme":"# Traffic counter Rock 5C \n![ScreenshotTraffic](https://github.com/user-attachments/assets/f284ed89-179b-40c2-8fc2-0bf3fc0e7e50)\n\n## Traffic counter with a camera on a bare RK3566 / RK3568 / RK3588. \u003cbr/\u003e\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\u003cbr/\u003e\u003cbr/\u003e\nSpecially made for a Raspberry Pi 4, see [Q-engineering deep learning examples](https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html)\u003cbr\u003e\n\n------------\n\n## Introduction.\nA fully functional traffic counter with a camera working on a bare Rock 5C.\nHighlights:\n- Stand alone.\n- Lane selection.\n- MQTT messages.\n- JSON messages.\n- Live web viewer.\n- JSON settings.\n- RTSP CCTV streaming.\n- Debug screens.\n\n------------\n\nhttps://github.com/user-attachments/assets/9c7c9156-a5a2-4000-9dca-409b27980903\n\n------------\n\n## Dependencies.\nTo run the application, you have to:\n- Optional: Code::Blocks installed. (```$ sudo apt-get install codeblocks```)\n\n### Installing the dependencies.\nStart with the usual \n```shell\n$ sudo apt-get update \n$ sudo apt-get upgrade\n$ sudo apt-get install curl libcurl4\n$ sudo apt-get install cmake wget\n```\n#### OpenCV\nFollow the Raspberry Pi 4 [guide](https://qengineering.eu/install-opencv-on-raspberry-64-os.html). Or:\n```shell\n$ sudo apt-get install libopencv-dev\n```\n#### Eigen3\n```shell\n$ sudo apt-get install libeigen3-dev\n```\n#### gflags\n```shell\n$ sudo apt-get install libgflags-dev\n```\n#### JSON for C++\nwritten by [Niels Lohmann](https://github.com/nlohmann).\n```shell\n$ cd ~\n$ git clone --depth=1 https://github.com/nlohmann/json.git\n$ cd json\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make -j4\n$ sudo make install\n$ sudo ldconfig\n```\n#### paho.mqtt (MQTT client)\n```shell\n$ cd ~\n$ git clone --depth=1 https://github.com/eclipse/paho.mqtt.c.git\n$ cd paho.mqtt.c\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make -j4\n$ sudo make install\n$ sudo ldconfig\n```\n#### Mosquitto (MQTT broker)\n```shell\n$ sudo apt-get install mosquitto\n```\n\n------------\n\n## Installing the app.\nDownload the software.\u003cbr/\u003e\n```\n$ git clone https://github.com/Qengineering/Traffic-Counter-Rock5C.git\n```\nYour folder must now look like this: \u003cbr/\u003e \n```\n.\n├── CMakeLists.txt\n├── config.json\n├── include\n│   ├── BYTETracker.h\n│   ├── dataType.h\n│   ├── General.h\n│   ├── kalmanFilter.h\n│   ├── lapjv.h\n│   ├── MJPG_sender.h\n│   ├── MJPGthread.h\n│   ├── MQTT.h\n│   ├── Numbers.h\n│   ├── postprocess.h\n│   ├── STrack.h\n│   ├── TChannel.h\n│   └── Tjson.h\n├── models\n│   ├── yolov5m.rknn\n│   ├── yolov5n.rknn\n│   ├── yolov5s_relu.rknn\n│   └── yolov5s.rknn\n├── src\n│   ├── BYTETracker.cpp\n│   ├── kalmanFilter.cpp\n│   ├── lapjv.cpp\n│   ├── main.cpp\n│   ├── main_video.cpp\n│   ├── MJPG_sender.cpp\n│   ├── MJPGthread.cpp\n│   ├── MQTT.cpp\n│   ├── postprocess.cpp\n│   ├── STrack.cpp\n│   ├── TChannel.cpp\n│   ├── Tjson.cpp\n│   └── utils.cpp\n├── Traffic.cbp\n└── Traffic.mp4\n```\n------------\n\n## Running the app.\nYou can use **Code::Blocks**.\n- Load the project file *.cbp in Code::Blocks.\n- Select _Release_, not Debug.\n- Compile and run with F9.\n- You can alter command line arguments with _Project -\u003e Set programs arguments..._ \n\nOr use **Cmake**.\n```shell\n$ cd *MyDir*\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make -j4\n```\n------------\n\n## Settings.\nAll important settings are stored in the `config.json`\u003cbr\u003e\nYou can alter these to your liking. Please note the use of commas after each line, except the last one.\u003cbr\u003e\n```json\n{\n    \"VERSION\": \"1.0.0.0\",\n\n    \"MQTT_ON\": true,\n    \"MQTT_SERVER_example\": \"broker.hivemq.com:1883\",\n    \"MQTT_SERVER\": \"localhost:1883\",\n    \"MQTT_CLIENT_ID\": \"Arrow\",\n    \"MQTT_TOPIC\": \"traffic\",\n    \"DEVICE_NAME\": \"highway 12\",\n    \"ANNOTATE\": true,\n\n    \"STREAM_example1\": \"rtsp://admin:L231C865@192.168.178.41:554/stream1\",\n    \"STREAM_example2\": \"RaspiCam\",\n    \"STREAM\": \"Traffic.mp4\",\n\n    \"BORDER_X1\": 10,\n    \"BORDER_Y1\": 300,\n    \"BORDER_X2\": 450,\n    \"BORDER_Y2\": 300,\n\n    \"JSON_PORT\": 8070,\n    \"MJPEG_PORT\": 8090,\n    \"MJPEG_WIDTH\": 640,\n    \"MJPEG_HEIGHT\": 480,\n\n    \"MESSAGE_TIME\": 2,\n\n    \"PARAM_MODEL\": \"./models/yolo-fastestv2-opt.param\",\n    \"BIN_MODEL\": \"./models/yolo-fastestv2-opt.bin\"\n}\n```\n\n| Global parameter | Comment |\n| ----      | ---- |\n| VERSION   | Current version. |\n| MQTT_ON | Enable MQTT messages. 'true-false'. |\n| MQTT_SERVER | MQTT server. Default `localhost:1883` |\n| MQTT_CLIENT_ID | MQTT client ID. Default `Arrow` |\n| MQTT_TOPIC | MQTT topic. Default `traffic` |\n| DEVICE_NAME | Name of the camera, used in the MQTT messages. |\n| ANNOTATE | Show lines, boxes and numbers in live view. Default `true` |\n| STREAM | The used input source.\u003cbr\u003eIt can be a video or a `RaspiCam`, or an RTSP stream, like CCTV cameras. |\n| BORDER_X1 | Left X position of the imaginary borderline. |\n| BORDER_Y1 | Left Y position of the imaginary borderline. |\n| BORDER_X2 | Right X position of the imaginary borderline. |\n| BORDER_Y2 | Right Y position of the imaginary borderline. |\n| JSON_PORT | The JSON message port number.|\n| MJPEG_PORT | The thumbnail browser overview. |\n| MJPEG_WIDTH | Thumbnail width |\n| MJPEG_HEIGHT | Thumbnail height |\n| MESSAGE_TIME | Define the interval between (MQTT) messages in seconds. Default 2. |\n| PARAM_MODEL | Used nccn DNN model (parameters). |\n| BIN_MODEL | Used nccn DNN model (weights). |\n\n------------\n\n![Screenshot from 2024-11-11 14-07-00](https://github.com/user-attachments/assets/492d8264-47e9-4437-abf0-f9c0a14778e2)\n\n------------\n\n## Debug.\nYou can use debug mode to find the optimal position for the borderline.\u003cbr\u003e \nTo enable debug mode, start the app with the --debug flag set to true:\u003cbr\u003e\n```shell\n./Traffic --debug=true\n```\nAlternatively, you can modify the command line argument in Code::Blocks by navigating to Project -\u003e Set programs arguments...\u003cbr\u003e \nIn debug mode, you’ll see the tail of each vehicle. When a vehicle’s tail crosses the imaginary borderline, it is added to the count.\u003cbr\u003e \nAt this point, the bounding box is highlighted, which helps in identifying any missed vehicles.\u003cbr\u003e\u003cbr\u003e\n\nhttps://github.com/user-attachments/assets/a0c47f52-f53c-41e8-b216-f17174b6b1ed\n\n------------\n\n## MQTT messages.\nYou can receive MQTT messages locally at localhost:1883, the default setting. Messages are printed to the terminal.\u003cbr\u003e \nWhen connected to the internet, you can send MQTT messages to any broker you choose, such as broker.hivemq.com:1883.\u003cbr\u003e \nThe app only sends messages when the MQTT_ON setting is set to true. The refresh rate, in seconds, is determined by MESSAGE_TIME.\u003cbr\u003e \nAt midnight, all cumulative counts are reset.\u003cbr\u003e\u003cbr\u003e \nYou can also follow the messages in a web browser. To do so, enter the port number after the IP address of your Raspberry Pi.\u003cbr\u003e\u003cbr\u003e\n![2024-11-11 15_22_51-192 168 178 87_8070 - Brave](https://github.com/user-attachments/assets/36d9ffcc-c66d-4da2-adaa-cbd45d19b6d6)\n\n------------\n\n## Preview.\nIf your Raspberry Pi is connected to the internet, you can view live footage in a browser.\u003cbr\u003e\nSimply combine the Raspberry Pi’s IP address with the MJPEG_PORT number specified in the settings to access the camera feed.\u003cbr\u003e\u003cbr\u003e\n![2024-11-11 15_21_32-192 168 178 87_8090 - Brave](https://github.com/user-attachments/assets/567fed46-b240-4450-b3d2-f5a07471f88d)\n\n\n------------\n\n[![paypal](https://qengineering.eu/images/TipJarSmall4.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=CPZTM5BB3FCYL) \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqengineering%2Ftraffic-counter-rock5c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqengineering%2Ftraffic-counter-rock5c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqengineering%2Ftraffic-counter-rock5c/lists"}