diff --git a/.github/workflows/python_environment.yml b/.github/workflows/python_environment.yml deleted file mode 100644 index 7782d4a..0000000 --- a/.github/workflows/python_environment.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Python Environment - -on: - push: - branches: [ main ] - paths: - - 'Controller/**' - - 'Training_Process/**' - - '.github/workflows/python_environment.yml' - pull_request: - branches: [ main ] - paths: - - 'Controller/**' - - 'Training_Process/**' - - '.github/workflows/python_environment.yml' - -jobs: - build: - runs-on: ${{matrix.os}} - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.7", "3.8", "3.9", "3.10"] - exclude: - - os: macos-latest - python-version: "3.7" - - os: windows-latest - python-version: "3.7" - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r Environment_Setup/requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68bc17f --- /dev/null +++ b/.gitignore @@ -0,0 +1,160 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/Controller/mecanum_control_bot.py b/Controller/mecanum_control_bot.py deleted file mode 100644 index c9356ec..0000000 --- a/Controller/mecanum_control_bot.py +++ /dev/null @@ -1,322 +0,0 @@ -""" -CVPRO v1.0.0. -Code Developed by Augustin Rajkumar, Suresh Balaji, E.V.V Thrilok kumar, and Meritus R & D Team - August 31, 2023. -Copyright © 2023 Meritus R & D Team. All rights reserved. -This program is the intellectual property of Meritus AI, and may not be distributed -or reproduced without explicit authorization from the copyright holder. -------------------------------------------------------------------------------------------------------------------- -This script helps in Controlling the bot with keyboard keybinding. -Such as: - w - forward - s - backward - a - Move sideways left - d - Move sideways right - z - Move diagonal left\r - x - Move diagonal right\r - c - Move around a blend left\r - v - Move around a blend right\r - e - Rotation left\r - r - Rotation right\r - f - Rotation around the central point of one axle in left\r - g - Rotation around the central point of one axle in right\r -esc - quit -""" - -# Import Packages -import sys -import socket -import argparse -import pygame -from paho.mqtt import client as mqtt_client -from pygame.locals import ( - K_ESCAPE, - KEYDOWN, - KEYUP, - QUIT, - K_w, K_a, K_s, K_d, - K_z, K_x, K_c, K_v, - K_e, K_r, K_f, K_g, -) - -# screen color -white = (255, 255, 255) -black = (0, 0, 0) -blue = (0, 0, 128) -red = (200, 0, 0) - -# Mqtt Server connection -BROKER = "192.168.4.2" #"broker.hivemq.com" #"192.168.168.94" # "broker.emqx.io" -PORT = 1883 -TOPIC = "cvpro" -# generate client ID with pub prefix randomly -CLIENT_ID = "python-mqtt" -USERNAME = "cvpro" -PASSWORD = "cvpro" - -parser = argparse.ArgumentParser(description="Control the Bot.") -parser.add_argument( - "-c", type=int, default=255, help="integer values to send to bot" -) - -args = parser.parse_args() -x = args.c - -if x > 255: - print("High speed! You should maintain a value under 255.") - # pygame.quit() - sys.exit() -elif x < 200: - print("Low speed! You should maintain a value above 200.") - # pygame.quit() - sys.exit() -else: - print("Your Speed limit 🏎️ --> ", x) - -# Instructions -def caution(): - """ - Display the content in Terminal window - """ - name= r""" - --- ---- ---- ---- ---- ---- ---- ---- ---- ---- - | Note: | - | If you want to stop ? | - | Click the 'X' on pygame window | - | or | - | Press 'esc' to Quit the pygame window | - --- ---- ---- ---- ---- ---- ---- ---- ---- ---- - - _________ ___ ___ _________ __________ ________ - / ________| \ \ / / | ____ \ | _____ \ / ______ \ - / / \ \ / / | | \ \ | | \ \ / / \ \ - | | \ \ / / | | | | | |_____/ / | | | | - | | \ \ / / | |____/ / | |_______/ | | | | - | | \ \ / / | |______/ | | \ \ | | | | - \ \________ \ \/ / | | | | \ \ \ \ _____/ / - \ _________| \____/ |__| |__| \__\ \ ________ / - - - ____ ____ ____________ __________ ____ _____ __ __ __ ____ ____ -| \ / | | _________| / ________| / \ | \ | | | | | | | \ / | -| \ / | | | / / / /\ \ | |\ \ | | | | | | | \ / | -| |\ \/ /| | | |_________ | | / / \ \ | | \ \ | | | | | | | |\ \/ /| | -| | \____/ | | | _________| | | / /____\ \ | | \ \ | | | | | | | | \____/ | | -| | | | | | | | / _______ \ | | \ \| | \ \ / / | | | | -| | | | | |_________ \ \_________ / / \ \ | | \ | | \ \_____/ / | | | | -|__| |__| |____________| \ __________| /__/ \__\ |__| \ ___| \_________/ |__| |__| - - - """ - print(name) - -def usage(): - """ - Display the control keys in Pygame window - """ - usage_str = """ - Make sure to keep the pygame window in focus!\r - - Use the following keys to drive the robot:\r - - \tw : Go forward\r - \ts : Go backward\r - \ta : Move sideways left\r - \td : Move sideways right\r - \tz : Move diagonal left\r - \tx : Move diagonal right\r - \tc : Move around a blend left\r - \tv : Move around a blend right\r - \te : Rotation left\r - \tr : Rotation right\r - \tf : Rotation around the central point of one axle in left\r - \tg : Rotation around the central point of one axle in right\r - \tesc : Quit \r - """ - return usage_str - -class Screen: - """ - Pygame Window Screen - """ - screen = None - font = None - y_pos = 0 - x_pos = 0 - - def setup_screen(self): - """ - Display the Font-size and resolution for screen - """ - pygame.display.set_caption("CVPRO Mecanum Keyboard Controller") - self.font = pygame.font.Font(None, 22) # Use system font - self.screen = pygame.display.set_mode([900, 650], pygame.RESIZABLE) - self.screen.fill(white) - text = usage() - print(text) - lines = text.strip().split("\r") - self.x_pos = 50 - self.y_pos = 50 - delimiter = ":" - for line in lines: - # create a text suface object - if delimiter in line: - space = " " if "\t" in line else "" - elements = line.strip().split(delimiter) - text = self.font.render( - space + elements[0].strip() + delimiter, True, blue - ) - self.screen.blit(text, (self.x_pos, self.y_pos)) - text = self.font.render(elements[1].strip(), True, black) - self.screen.blit(text, (self.x_pos + 200, self.y_pos)) - else: - text = self.font.render(line, True, red) - self.screen.blit(text, (self.x_pos, self.y_pos)) - pygame.display.update() - self.y_pos += 40 - -screen = Screen() - -def connect_mqtt(): - """ - Connection for MQTT server - """ - def on_connect(client, userdata, flags, return_code): - if return_code == 0: - print("Connected to MQTT Broker 🔗 ") - else: - print("Failed to connect, return code %d\n", return_code) - client = mqtt_client.Client(CLIENT_ID) - client.username_pw_set(USERNAME, PASSWORD) - client.on_connect = on_connect - try: - client.connect(BROKER, PORT) - - except ConnectionError as connectionerror: - print(f"Error connecting to MQTT broker: {connectionerror}") - return None - except socket.timeout: - print("Connection Time-out to MQTT broker ⌛️ ") - return None - return client - -def publish(client): - """ - To Publish the keys for controlling the bot. - """ - running = True - login = False - bot = False - camera = False - flashlight = False - msg = None - try: - while running: - for event in pygame.event.get(): - if event.type == KEYDOWN: # control the keys - if event.key == K_w: # moving forward - msg = f"{x}, {x}" - - elif event.key == K_s: # moving backward - msg = f"{-x}, {-x}" - - elif event.key == K_a: # moving sideways left - msg = f"{-30}, {30}" - - elif event.key == K_d: # moving sideways right - msg = f"{30}, {-30}" - - elif event.key == K_z: # moving diagonal left - msg = f"{-15}, {15}" - - elif event.key == K_x: # moving diagonal right - msg = f"{15}, {-15}" - - elif event.key == K_c: # moving around blend left - msg = f"{-60}, {60}" - - elif event.key == K_v: # moving around blend right - msg = f"{60}, {-60}" - - elif event.key == K_e: # Rotation left - msg = f"{-360}, {360}" - - elif event.key == K_r: # Rotation right - msg = f"{360}, {-360}" - - elif event.key == K_f: # Rotation around the central point of one axle in left - msg = f"{-120}, {120}" - - elif event.key == K_g: # Rotation around the central point of one axle in right - msg = f"{120}, {-120}" - - elif event.key == K_ESCAPE: # to quit the pygame - running = False - print("Control Screen - Quit🚪") - break - if msg is not None: - print("Message Published -->",msg) - result = client.publish(TOPIC, msg) - - if event.type == KEYUP: # Releasing the Keys - if event.key == K_ESCAPE: - msg = None - elif event.key == K_w: - msg = f"{0}, {0}" - elif event.key == K_s: - msg = f"{0}, {0}" - elif event.key == K_a: - msg = f"{0}, {0}" - elif event.key == K_d: - msg = f"{0}, {0}" - elif event.key == K_e: - msg = f"{0}, {0}" - elif event.key == K_r: - msg = f"{0}, {0}" - elif event.key == K_f: - msg = f"{0}, {0}" - elif event.key == K_g: - msg = f"{0}, {0}" - elif event.key == K_z: - msg = f"{0}, {0}" - elif event.key == K_x: - msg = f"{0}, {0}" - elif event.key == K_c: - msg = f"{0}, {0}" - elif event.key == K_v: - msg = f"{0}, {0}" - # print(msg) - if msg is not None: - print("Message published in KeyUP ",msg) - result = client.publish(TOPIC, msg) - - if event.type == QUIT: # close the pygame window - running = False - print("Control Screen - Exit ❌") - sys.exit() - # result = client.disconnect() - - if not running: - break # Break the outer loop - - except Exception as exception: - print(f"Exception in Publish: {exception}") - -def run(): - """ - To Run the client, calling the Mqtt Connection - """ - client = connect_mqtt() # calling the Mqtt Connection - - if client is None: # the client is not connected - print("MQTT connection failed. Exiting... 🚪") - return - - client.loop_start() - publish(client) - -# Main -if __name__ == "__main__": - caution() - pygame.init() - screen.setup_screen() - run() diff --git a/Controller/videostream_control_bot.py b/Controller/videostream_control_bot.py deleted file mode 100644 index 121bd4e..0000000 --- a/Controller/videostream_control_bot.py +++ /dev/null @@ -1,343 +0,0 @@ -""" -CVPRO v1.0.0. -Code Developed by Augustin Rajkumar, Suresh Balaji, E.V.V Thrilok kumar, and Meritus R & D Team - August 31, 2023. -Copyright © 2023 Meritus R & D Team. All rights reserved. -This program is the intellectual property of Meritus AI, and may not be distributed -or reproduced without explicit authorization from the copyright holder. ---------------------------------------------------------------------------------------- -This script helps in Video-Streaming and Controlling the bot with keyboard keybinding. -Such as: -Such as: - w - forward - s - backward - w + a - left - w + d - right - b - bot - f - flashlight - c - camera swapping - spacebar - login on\off - esc - quit -""" - -# Import Packages -import sys -import cv2 -import uuid -import base64 -import pygame -import socket -import argparse -import numpy as np -from paho.mqtt import client as mqtt_client -from pygame.locals import ( - K_SPACE, - K_ESCAPE, - KEYDOWN, - KEYUP, - QUIT, - K_w, - K_a, - K_s, - K_d, - K_b, - K_f, - K_c -) - -# screen color -white = (255, 255, 255) -black = (0, 0, 0) -blue = (0, 0, 128) -red = (200, 0, 0) - -# MQTT broker and TOPIC -BROKER = "192.168.4.2" #"broker.hivemq.com" -PORT = 1883 -TOPIC = "cvpro" -TOPIC2 = "video" - -# generate client ID with pub prefix randomly -# CLIENT_ID = "python-mqtt" -USERNAME = "cvpro" -PASSWORD = "cvpro" - -parser = argparse.ArgumentParser(description="Control the Bot.") -parser.add_argument("-c", type=int, default=255, help="integer values to send to bot") -args = parser.parse_args() -x = args.c -if x > 255: - print("High speed! You should maintain a value under 255.") - #pygame.quit() - sys.exit() -elif x < 200: - print("Low speed! You should maintain a value above 200.") - #pygame.quit() - sys.exit() -else: - print("Your Speed limit 🏎️ --> ", x) - -# Instructions -def caution(): - name= r""" - --- ---- ---- ---- ---- ---- ---- ---- ---- ---- - | Note: | - | If you want to stop ? | - | Click the 'X' on pygame window | - | or | - | Press 'esc' to Quit the pygame window | - --- ---- ---- ---- ---- ---- ---- ---- ---- ---- - - _________ ___ ___ _________ __________ ________ - / ________| \ \ / / | ____ \ | _____ \ / ______ \ - / / \ \ / / | | \ \ | | \ \ / / \ \ - | | \ \ / / | | | | | |_____/ / | | | | - | | \ \ / / | |____/ / | |_______/ | | | | - | | \ \ / / | |______/ | | \ \ | | | | - \ \________ \ \/ / | | | | \ \ \ \ _____/ / - \ _________| \____/ |__| |__| \__\ \ ________ / - - - """ - print(name) - -def on_connect(client, userdata, flags, rc): - if rc == 0: - print("Connected to MQTT Broker 🔗 ") - else: - print("Failed to connect, return code %d\n", rc) - -# Callback function for MQTT message -def on_message(client, userdata, msg): - print("Message was received") - if msg.payload is None: - print("Received an empty message payload.") - frame_data = base64.b64decode(msg.payload) - - if len(frame_data) == 0: - print("Received empty frame data.") - - frame = cv2.imdecode(np.frombuffer(frame_data, np.uint8), cv2.IMREAD_COLOR) - - if frame is None: - print("Failed to decode frame.") - # Flip the frame horizontally - # frame = cv2.flip(frame, 1) - # Convert the OpenCV frame to a Pygame surface - frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) - frame = np.rot90(frame, k=2) # Rotate 180 degrees counter-clockwise - frame = np.fliplr(frame) # Flip the frame horizontally - frame = pygame.surfarray.make_surface(frame) - # Update the video frame - video_frame.blit(frame, (0, 0)) - -# Set up the display -screen_width = 930 -screen_height = 600 -control_width = screen_width // 2 -video_width = screen_width - control_width -#screen-size -screen = pygame.display.set_mode((screen_width, screen_height)) -pygame.display.set_caption("CVPRO Keyboard Controller") - -# Define the left and right display surfaces -control_display = pygame.Surface((control_width, screen_height)) -video_display = pygame.Surface((video_width, screen_height)) -# print("video_width: ", video_width) -# print("screen_height: ", screen_height) - -def display_text(): - # Render and blit the usage text on the control display - usage_text = """ - Make sure to keep the pygame window in focus!\r - - Use the following keys to drive the robot:\r - - \tw : Go forward\r - \ts : Go backward\r - \tw + a : Turn slightly left (while driving)\r - \tw + d : Turn slightly right (while driving)\r - \tb : To Drive turn the bot on/off\r - \tf : Turn on/off Flashlight\r - \tc : Camera Swapping Mode\r - \tspace-bar : Data Collection Start/End\r - \tesc : Quit\r - """ - lines = usage_text.strip().split("\r") - line_height = 30 - # Render and blit the usage text on the control display - x_pos = 50 - y_pos = 50 - delimiter = ":" - for line in lines: - if delimiter in line: - space = " " if "\t" in line else "" - elements = line.strip().split(delimiter) - text = font.render(space + elements[0].strip() + delimiter, True, blue) - control_display.blit(text, (x_pos, y_pos)) - text = font.render(elements[1].strip(), True, black) - control_display.blit(text, (x_pos + 200, y_pos)) - else: - text = font.render(line, True, red) - control_display.blit(text, (x_pos, y_pos)) - y_pos += line_height - - -# Initalize the pygame screen -pygame.init() -caution() -# Font for usage information -font = pygame.font.Font(None, 20) - -# Initialize video frame -video_frame = pygame.Surface((465, 600)) - -# Generate a UUID version 4 -uuid_obj = uuid.uuid4() - -# Convert the UUID to a string -uuid_string = str(uuid_obj) - -# MQTT client setup -client = mqtt_client.Client(f"VideoReceiver-{uuid_string}") -client.username_pw_set(USERNAME, PASSWORD) -client.on_connect = on_connect -client.on_message = on_message -try: - client.connect(BROKER, PORT) -except ConnectionError as connectionerror: - print(f"Error connecting to MQTT broker: {connectionerror}") -except socket.timeout: - print("Connection Time-out to MQTT broker ⌛️ ") -# subscribe -client.subscribe(TOPIC2, qos=2) -client.loop_start() - -# Declare -running = True -login = False -bot = False -camera = False -flashlight = False -msg = None -# Main loop -while running: - for event in pygame.event.get(): - if event.type == KEYDOWN: # control the keys - if event.key == K_w: # moving forward - msg = f"{x}, {x}" - - elif event.key == K_s: # moving backward - msg = f"{-x}, {-x}" - - elif event.key == K_a: # moving left - if pygame.key.get_pressed()[K_w]: - msg = f"{-int(x * 0.75)}, {x}" - - elif event.key == K_d: # moving right - if pygame.key.get_pressed()[K_w]: - msg = f"{x}, {-int(x * 0.75)}" - - elif event.key == K_SPACE: # Data collection - if not login: - msg = "login_on" - # print("login start") - login = True - - elif login == True: - msg = "login_off" - # print("login stop") - login = False - if bot == True: # bot is turn-off when the login is off - print("Message Published as bot_off") - bot = False - - elif event.key == K_b: # to turn-on/off the bot - if not bot: - msg = "bot_on" - # print("bot on") - bot = True - else: - msg = "bot_off" - # print("bot off") - bot = False - - elif event.key == K_c: # camera swapping - if not camera: - msg = "front_camera" - # print("camera swap into Front-side") - camera = True - else: - msg = "back_camera" - # print("camera swap into Back-side") - camera = False - - elif event.key == K_f: # flashlight - if not flashlight: - msg = "flashlight_on" - # print("flashlight on") - flashlight = True - else: - msg = "flashlight_off" - # print("flashlight off") - flashlight = False - - elif event.key == K_ESCAPE: # to quit the pygame - running = False - print("Data Collection - Exit ❌") - break - if msg is not None: - print("Message Published -->", msg) - result = client.publish(TOPIC, msg) - - if event.type == KEYUP: # Releasing the Keys - if event.key in (K_SPACE, K_c, K_f, K_ESCAPE): - if event.key == K_SPACE: - msg = None - elif event.key == K_c: - msg = None - elif event.key == K_f: - msg = None - elif event.key == K_b: - msg = None - elif event.key == K_ESCAPE: - msg = None - - elif event.key == K_w: - msg = f"{0}, {0}" - elif event.key in [K_a, K_d]: - if pygame.key.get_pressed()[K_w]: - msg = f"{x}, {x}" - elif pygame.key.get_pressed()[K_s]: - msg = f"{-x}, {-x}" - else: - msg = f"{0}, {0}" - elif event.key == K_s: - msg = f"{0}, {0}" - # print(msg) - if msg is not None: - print("Message published in KeyUP ", msg) - result = client.publish(TOPIC, msg) - - if event.type == QUIT: # close the pygame window - running = False - print("Data Collection - Quit 🚪") - sys.exit() - - # Clear the screens - control_display.fill(white) - video_display.fill(white) - display_text() - # Blit the video frame on the video display - video_display.blit(video_frame, (0, 0)) - - # Blit the control and video displays onto the main screen - screen.blit(control_display, (0, 0)) - screen.blit(video_display, (control_width, 0)) - - pygame.display.update() - -# Clean up resources -cv2.destroyAllWindows() -client.disconnect() -#pygame.quit() -sys.exit() \ No newline at end of file diff --git a/Environment_Setup/requirements.txt b/Environment_Setup/requirements.txt deleted file mode 100644 index 9999f46..0000000 --- a/Environment_Setup/requirements.txt +++ /dev/null @@ -1,16 +0,0 @@ -tqdm -numpy -pygame~=2.4.0 -pandas -pillow -notebook -seaborn -paho-mqtt -matplotlib -scikit-learn -opencv-python~=4.5.4.60 - - - - - diff --git a/Meritus-CVPRO-main/Controller/activate_cvpro.bat b/Meritus-CVPRO-main/Controller/activate_cvpro.bat new file mode 100644 index 0000000..3d45b3f --- /dev/null +++ b/Meritus-CVPRO-main/Controller/activate_cvpro.bat @@ -0,0 +1,81 @@ +@echo off + +title Conda Environment - Build and Activate + +set "userProfile=%USERPROFILE%" + +:checkInternetConnection +ping 8.8.8.8 -n 1 -w 1000 >nul +if errorlevel 1 ( + echo Please connect to the internet and try again. + exit /b +) + +:waitForInput +echo Hi! Please Ensure Internet Connection! +set /p userInput="Give me a command - 'build' or 'activate' or 'deactivate': " +if /i "%userInput%"=="build" ( + echo Creating a Virtual Environment:- cvpro ... + call "%userProfile%\miniconda3\Scripts\activate.bat" "%userProfile%\miniconda3" + call conda create -n cvpro python=3.9 -y + echo Building the Environment... + + if errorlevel 1 ( + echo Build failed. + ) else if errorlevel 0 ( + echo Build is Successful. + echo. + echo Activating the Environment + call conda activate cvpro + echo cvpro Environment is Built and Activated... + echo. + echo Now you are ready for Installation Process. + echo. + echo Type 'install_cvpro' to Install the Dependencies + ) + +) else if /i "%userInput%"=="activate" ( + call "%userProfile%\miniconda3\Scripts\activate.bat" "%userProfile%\miniconda3" + REM Check if environment exists before activating + call conda info --envs | findstr /C:"cvpro" > nul + if errorlevel 1 ( + echo Environment cvpro not found. + echo Activation failed. + ) else ( + call conda activate cvpro + echo cvpro Environment is Activated... + echo. + echo For Data Collection Process: + echo ---------------------------- + echo. + echo 1. Please Disconnect the Internet, and connect the Bot with the System. Ensure the Connected IPv4 Address is: 192.168.4.2 + echo 2. Type 'launch_server' to Launch the MQTT Server to run the Bot! + echo 3. Type 'run_cvpro' to begin the Data Collection Process! + echo. + echo For Training Process: + echo --------------------- + echo. + echo 1. Ensure your Bot is disconnected from the System as well as the Application. + echo 2. Type 'train_cvpro' to begin the Training Process! + echo. + + ) +) else if /i "%userInput%"=="deactivate" ( + call "%userProfile%\miniconda3\Scripts\activate.bat" "%userProfile%\miniconda3" + REM Check if environment exists before activating + call conda info --envs | findstr /C:"cvpro" > nul + if errorlevel 1 ( + echo Environment cvpro not found. + echo De-Activation failed. + ) else ( + call conda activate cvpro + call conda.bat deactivate + echo. + echo cvpro Environment is De-Activated + ) + +) else ( + echo Invalid command. Please enter 'build' or 'activate' or 'deactivate'. + echo. + goto waitForInput +) diff --git a/Controller/control_bot.py b/Meritus-CVPRO-main/Controller/control_bot.py similarity index 84% rename from Controller/control_bot.py rename to Meritus-CVPRO-main/Controller/control_bot.py index 2a56478..f5b4042 100644 --- a/Controller/control_bot.py +++ b/Meritus-CVPRO-main/Controller/control_bot.py @@ -30,6 +30,10 @@ KEYDOWN, KEYUP, QUIT, + K_UP, + K_DOWN, + K_LEFT, + K_RIGHT, K_w, K_a, K_s, @@ -54,24 +58,25 @@ USERNAME = "cvpro" PASSWORD = "cvpro" -parser = argparse.ArgumentParser(description="Control the Bot.") -parser.add_argument( - "-c", type=int, default=255, help="integer values to send to bot" -) - -args = parser.parse_args() -x = args.c - -if x > 255: - print("High speed! You should maintain a value under 255.") - # pygame.quit() - sys.exit() -elif x < 200: - print("Low speed! You should maintain a value above 200.") - # pygame.quit() - sys.exit() -else: - print("Your Speed limit 🏎️ --> ", x) +def speed_input(): + global x + user_input = input("Enter a valid Speed Limit (170-255):") + + if not user_input: + print("No input provided. Please enter a valid speed limit.") + speed_input() + return + + x = int(user_input) + + if x > 255: + print("High speed! You should maintain a value under 255! Default is 220.") + speed_input() + elif x < 200: + print("Low speed! You should maintain a value above 200! Default is 220.") + speed_input() + else: + print("Your Speed limit 🏎️ --> ", x) # Instructions def caution(): @@ -172,6 +177,7 @@ def on_connect(client, userdata, flags, return_code): else: print("Failed to connect, return code %d\n", return_code) client = mqtt_client.Client(CLIENT_ID) + #client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, CLIENT_ID) client.username_pw_set(USERNAME, PASSWORD) client.on_connect = on_connect try: @@ -199,17 +205,20 @@ def publish(client): while running: for event in pygame.event.get(): if event.type == KEYDOWN: # control the keys - if event.key == K_w: # moving forward + if event.key in (K_UP, K_w): # moving forward msg = f"{x}, {x}" - elif event.key == K_s: # moving backward + elif event.key in (K_DOWN, K_s): # moving backward msg = f"{-x}, {-x}" - elif event.key == K_a: # moving left - if pygame.key.get_pressed()[K_w]: + elif event.key in (K_LEFT, K_a): # moving left + # Check if the UP key or W key is pressed for diagonal movement + if pygame.key.get_pressed()[K_UP] or pygame.key.get_pressed()[K_w]: msg = f"{-int(x * 0.75)}, {x}" - elif event.key == K_d: # moving right - if pygame.key.get_pressed()[K_w]: + + elif event.key in (K_RIGHT, K_d): # moving right + # Check if the UP key or W key is pressed for diagonal movement + if pygame.key.get_pressed()[K_UP] or pygame.key.get_pressed()[K_w]: msg = f"{x}, {-int(x * 0.75)}" elif event.key == K_SPACE: # Data collection @@ -289,6 +298,18 @@ def publish(client): msg = f"{0}, {0}" elif event.key == K_s: msg = f"{0}, {0}" + + elif event.key == K_UP: + msg = f"{0}, {0}" + elif event.key in [K_LEFT, K_RIGHT]: + if pygame.key.get_pressed()[K_UP]: + msg = f"{x}, {x}" + elif pygame.key.get_pressed()[K_DOWN]: + msg = f"{-x}, {-x}" + else: + msg = f"{0}, {0}" + elif event.key == K_DOWN: + msg = f"{0}, {0}" # print(msg) if msg is not None: print("Message published in KeyUP ",msg) @@ -321,7 +342,8 @@ def run(): # Main if __name__ == "__main__": + speed_input() caution() pygame.init() screen.setup_screen() - run() + run() \ No newline at end of file diff --git a/Meritus-CVPRO-main/Controller/install.bat b/Meritus-CVPRO-main/Controller/install.bat new file mode 100644 index 0000000..0ad2b41 --- /dev/null +++ b/Meritus-CVPRO-main/Controller/install.bat @@ -0,0 +1,81 @@ +@echo off +title Installation of Libraries +set "userProfile=%USERPROFILE%" + +:checkInternetConnection +ping 8.8.8.8 -n 1 -w 1000 >nul +if errorlevel 1 ( + echo Please connect to the internet and try again. + exit /b +) + +:waitForInput +set /p userInput="Do you have a valid Internet Connection? - 'y' or 'n': " +if /i "%userInput%"=="y" ( + echo Installing dependencies................... + + cd "%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Controller" + + call %userProfile%\miniconda3\envs\cvpro\python.exe -m pip install --upgrade pip + REM call conda install cudatoolkit -y + REM call conda install cudnn -y + call pip install tensorflow~=2.9.0 + + call cd %userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Environment_Setup + + call pip install -r requirements.txt + + + + if errorlevel 1 ( + + call :echoredError Installation failed! + echo. + call :echoblueError Check for the following: + echo. + echo 1. Please ensure your Internet Connectivity is Stable. + echo 2. Please ensure you have activated the 'cvpro' Environment. + echo 3. Please ensure you have followed the execution steps in the order given. + echo. + + ) else ( + + echo. + call :echogreenError Installation is Completed! + echo. + + call :echoblueError For Data Collection Process: + echo ---------------------------- + echo. + echo 1. Please Disconnect the Internet, and connect the Bot with the System. Ensure the Connected IPv4 Address is: 192.168.4.2 + echo 2. Type 'launch_server' to Launch the MQTT Server to run the Bot! + echo 3. Type 'run_cvpro' to begin the Data Collection Process! + echo. + echo For Training Process: + echo --------------------- + echo. + echo 1. Ensure your Bot is disconnected from the System as well as the Application. + echo 2. Type ' train_cvpro ' to begin the Training Process! + ) + +) else if /i "%userInput%"=="n" ( + echo Please do have a valid Internet Connection for the Installation Process. +) else ( + echo Invalid command. Please enter 'y' or 'n'. + echo. + goto waitForInput +) + + +:echoredError +echo %* +exit /b + +:echoblueError +echo %* +exit /b + +:echogreenError +echo %* +exit /b + diff --git a/Meritus-CVPRO-main/Controller/launch_mosquitto.bat b/Meritus-CVPRO-main/Controller/launch_mosquitto.bat new file mode 100644 index 0000000..0db6414 --- /dev/null +++ b/Meritus-CVPRO-main/Controller/launch_mosquitto.bat @@ -0,0 +1,5 @@ +@echo off +set "userProfile=%USERPROFILE%" +title MQTT Server +cd "%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Environment_Setup" +"C:\Program Files\mosquitto\mosquitto.exe" -v -c mqtt_conf.conf diff --git a/Meritus-CVPRO-main/Controller/test_run.bat b/Meritus-CVPRO-main/Controller/test_run.bat new file mode 100644 index 0000000..1802305 --- /dev/null +++ b/Meritus-CVPRO-main/Controller/test_run.bat @@ -0,0 +1,39 @@ +@echo off +title Data Collection Process +set "userProfile=%USERPROFILE%" +cd "%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Controller" + +call cls + +:waitForChoice +set /p userInput="Enter your choice - 'control' or 'videostream': " + +if /i "%userInput%"=="control" ( + call :run_bot control_bot.py +) else if /i "%userInput%"=="videostream" ( + call :run_bot videostream_control_bot.py +) else ( + echo Invalid choice. Please enter 'control' or 'videostream'. + echo. + goto waitForChoice +) + +goto :eof + +:run_bot +:waitForInput +set /p userInput="Is your Bot connected with the Application? - 'y' or 'n': " +if /i "%userInput%"=="y" ( + echo Running the Bot....... +) else if /i "%userInput%"=="n" ( + echo Please connect the bot with your Application! + exit /b +) else ( + echo Invalid command. Please enter 'y' or 'n'. + echo. + goto waitForInput +) +call python %1 +echo. +echo Type 'run_cvpro' or 'train_cvpro' according to your requirement! +goto :eof diff --git a/Meritus-CVPRO-main/Controller/train.bat b/Meritus-CVPRO-main/Controller/train.bat new file mode 100644 index 0000000..412d2ad --- /dev/null +++ b/Meritus-CVPRO-main/Controller/train.bat @@ -0,0 +1,52 @@ +@echo off +title Training Process +set "userProfile=%USERPROFILE%" +cd "%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Training_Process" + +call cls + +:waitForInput +set /p userInput="Is your Bot Disconnected from the Application and System? - 'y' or 'n': " +if /i "%userInput%"=="y" ( + echo Initializing the Training Process! +) else if /i "%userInput%"=="n" ( + echo Please disconnect the Bot from your Application and the System! + exit /b +) else ( + echo Invalid command. Please enter 'y' or 'n'. + echo. + goto :waitForInput +) + +set /p batchSize="Give me a valid Batch Size [16, 32, 64, 128]: " +if "%batchSize%"=="" set "batchSize=32" +echo My Batch Size: %batchSize% +echo. + + +set /p epochValue="Give me a valid Epoch Value [5, 10, 20, 25, 50, 100]: " +if "%epochValue%"=="" set "epochValue=5" +echo My Epoch Value: %epochValue% +echo. + + +set /p learningRate="Give me a valid Learning Rate [0.00001, 0.0001, 0.001, 0.01, 0.1, 1]: " +if "%learningRate%"=="" set "learningRate=0.0001" +echo My Learning Rate: %learningRate% +echo. + +echo Deleting the Garbage Files, that are not required for Training Process.......... + +call :delFiles +timeout /t 2 >nul + +echo Garbage Files are Deleted + +call python main.py -b %batchSize% -e %epochValue% -lr %learningRate% + +:delFiles +for /r %%i in (gitkeep) do ( + if exist "%%i" ( + del "%%i" /q /f + ) +) \ No newline at end of file diff --git a/Meritus-CVPRO-main/Controller/videostream_control_bot.py b/Meritus-CVPRO-main/Controller/videostream_control_bot.py new file mode 100644 index 0000000..4aa6d1b --- /dev/null +++ b/Meritus-CVPRO-main/Controller/videostream_control_bot.py @@ -0,0 +1,369 @@ +""" +CVPRO v1.0.0. +Code Developed by Augustin Rajkumar, Suresh Balaji, E.V.V Thrilok kumar, and Meritus R & D Team - August 31, 2023. +Copyright © 2023 Meritus R & D Team. All rights reserved. +This program is the intellectual property of Meritus AI, and may not be distributed +or reproduced without explicit authorization from the copyright holder. +--------------------------------------------------------------------------------------- +This script helps in Video-Streaming and Controlling the bot with keyboard keybinding. +Such as: +Such as: + w - forward + s - backward + w + a - left + w + d - right + b - bot + f - flashlight + c - camera swapping + spacebar - login on\off + esc - quit +""" + +# Import Packages +import sys +import cv2 +import uuid +import base64 +import pygame +import socket +import argparse +import numpy as np +from paho.mqtt import client as mqtt_client +from pygame.locals import ( + K_SPACE, + K_ESCAPE, + KEYDOWN, + KEYUP, + QUIT, + K_UP, + K_DOWN, + K_LEFT, + K_RIGHT, + K_w, + K_a, + K_s, + K_d, + K_b, + K_f, + K_c +) + +# screen color +white = (255, 255, 255) +black = (0, 0, 0) +blue = (0, 0, 128) +red = (200, 0, 0) + +# MQTT broker and TOPIC +BROKER = "192.168.4.2" #"broker.hivemq.com" +PORT = 1883 +TOPIC = "cvpro" +TOPIC2 = "video" + +# generate client ID with pub prefix randomly +# CLIENT_ID = "python-mqtt" +USERNAME = "cvpro" +PASSWORD = "cvpro" + +def speed_input(): + global x + user_input = input("Enter a valid Speed Limit (170-255):") + + if not user_input: + print("No input provided. Please enter a valid speed limit.") + speed_input() + return + + x = int(user_input) + + if x > 255: + print("High speed! You should maintain a value under 255! Default is 220.") + speed_input() + elif x < 200: + print("Low speed! You should maintain a value above 200! Default is 220.") + speed_input() + else: + print("Your Speed limit 🏎️ --> ", x) + +def main(): + + # Instructions + def caution(): + name= r""" + --- ---- ---- ---- ---- ---- ---- ---- ---- ---- + | Note: | + | If you want to stop ? | + | Click the 'X' on pygame window | + | or | + | Press 'esc' to Quit the pygame window | + --- ---- ---- ---- ---- ---- ---- ---- ---- ---- + + _________ ___ ___ _________ __________ ________ + / ________| \ \ / / | ____ \ | _____ \ / ______ \ + / / \ \ / / | | \ \ | | \ \ / / \ \ + | | \ \ / / | | | | | |_____/ / | | | | + | | \ \ / / | |____/ / | |_______/ | | | | + | | \ \ / / | |______/ | | \ \ | | | | + \ \________ \ \/ / | | | | \ \ \ \ _____/ / + \ _________| \____/ |__| |__| \__\ \ ________ / + + + """ + print(name) + + def on_connect(client, userdata, flags, rc): + if rc == 0: + print("Connected to MQTT Broker 🔗 ") + else: + print("Failed to connect, return code %d\n", rc) + + # Callback function for MQTT message + def on_message(client, userdata, msg): + print("Message was received") + if msg.payload is None: + print("Received an empty message payload.") + frame_data = base64.b64decode(msg.payload) + + if len(frame_data) == 0: + print("Received empty frame data.") + + frame = cv2.imdecode(np.frombuffer(frame_data, np.uint8), cv2.IMREAD_COLOR) + + if frame is None: + print("Failed to decode frame.") + # Flip the frame horizontally + # frame = cv2.flip(frame, 1) + # Convert the OpenCV frame to a Pygame surface + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + frame = np.rot90(frame, k=2) # Rotate 180 degrees counter-clockwise + frame = np.fliplr(frame) # Flip the frame horizontally + frame = pygame.surfarray.make_surface(frame) + # Update the video frame + video_frame.blit(frame, (0, 0)) + + # Set up the display + screen_width = 930 + screen_height = 600 + control_width = screen_width // 2 + video_width = screen_width - control_width + #screen-size + screen = pygame.display.set_mode((screen_width, screen_height)) + pygame.display.set_caption("CVPRO Keyboard Controller") + + # Define the left and right display surfaces + control_display = pygame.Surface((control_width, screen_height)) + video_display = pygame.Surface((video_width, screen_height)) + # print("video_width: ", video_width) + # print("screen_height: ", screen_height) + + def display_text(): + # Render and blit the usage text on the control display + usage_text = """ + Make sure to keep the pygame window in focus!\r + + Use the following keys to drive the robot:\r + + \tw : Go forward\r + \ts : Go backward\r + \tw + a : Turn slightly left (while driving)\r + \tw + d : Turn slightly right (while driving)\r + \tb : To Drive turn the bot on/off\r + \tf : Turn on/off Flashlight\r + \tc : Camera Swapping Mode\r + \tspace-bar : Data Collection Start/End\r + \tesc : Quit\r + """ + lines = usage_text.strip().split("\r") + line_height = 30 + # Render and blit the usage text on the control display + x_pos = 50 + y_pos = 50 + delimiter = ":" + for line in lines: + if delimiter in line: + space = " " if "\t" in line else "" + elements = line.strip().split(delimiter) + text = font.render(space + elements[0].strip() + delimiter, True, blue) + control_display.blit(text, (x_pos, y_pos)) + text = font.render(elements[1].strip(), True, black) + control_display.blit(text, (x_pos + 200, y_pos)) + else: + text = font.render(line, True, red) + control_display.blit(text, (x_pos, y_pos)) + y_pos += line_height + + + # Initalize the pygame screen + pygame.init() + caution() + # Font for usage information + font = pygame.font.Font(None, 20) + + # Initialize video frame + video_frame = pygame.Surface((465, 600)) + + # Generate a UUID version 4 + uuid_obj = uuid.uuid4() + + # Convert the UUID to a string + uuid_string = str(uuid_obj) + + # MQTT client setup + client = mqtt_client.Client(f"VideoReceiver-{uuid_string}") + client.username_pw_set(USERNAME, PASSWORD) + client.on_connect = on_connect + client.on_message = on_message + try: + client.connect(BROKER, PORT) + except ConnectionError as connectionerror: + print(f"Error connecting to MQTT broker: {connectionerror}") + except socket.timeout: + print("Connection Time-out to MQTT broker ⌛️ ") + # subscribe + client.subscribe(TOPIC2, qos=2) + client.loop_start() + + # Declare + running = True + login = False + bot = False + camera = False + flashlight = False + msg = None + # Main loop + while running: + for event in pygame.event.get(): + if event.type == KEYDOWN: # control the keys + if event.key in (K_w,K_UP): # moving forward + msg = f"{x}, {x}" + + elif event.key in (K_s,K_DOWN): # moving backward + msg = f"{-x}, {-x}" + + elif event.key in (K_a,K_LEFT): # moving left + if pygame.key.get_pressed()[K_w] or pygame.key.get_pressed()[K_UP] : + msg = f"{-int(x * 0.75)}, {x}" + + elif event.key in (K_d,K_RIGHT): # moving right + if pygame.key.get_pressed()[K_w] or pygame.key.get_pressed()[K_UP]: + msg = f"{x}, {-int(x * 0.75)}" + + elif event.key == K_SPACE: # Data collection + if not login: + msg = "login_on" + # print("login start") + login = True + + elif login == True: + msg = "login_off" + # print("login stop") + login = False + if bot == True: # bot is turn-off when the login is off + print("Message Published as bot_off") + bot = False + + elif event.key == K_b: # to turn-on/off the bot + if not bot: + msg = "bot_on" + # print("bot on") + bot = True + else: + msg = "bot_off" + # print("bot off") + bot = False + + elif event.key == K_c: # camera swapping + if not camera: + msg = "front_camera" + # print("camera swap into Front-side") + camera = True + else: + msg = "back_camera" + # print("camera swap into Back-side") + camera = False + + elif event.key == K_f: # flashlight + if not flashlight: + msg = "flashlight_on" + # print("flashlight on") + flashlight = True + else: + msg = "flashlight_off" + # print("flashlight off") + flashlight = False + + elif event.key == K_ESCAPE: # to quit the pygame + running = False + print("Data Collection - Exit ❌") + break + if msg is not None: + print("Message Published -->", msg) + result = client.publish(TOPIC, msg) + + if event.type == KEYUP: # Releasing the Keys + if event.key in (K_SPACE, K_c, K_f, K_ESCAPE): + if event.key == K_SPACE: + msg = None + elif event.key == K_c: + msg = None + elif event.key == K_f: + msg = None + elif event.key == K_b: + msg = None + elif event.key == K_ESCAPE: + msg = None + + elif event.key == K_w: + msg = f"{0}, {0}" + elif event.key in [K_a, K_d]: + if pygame.key.get_pressed()[K_w]: + msg = f"{x}, {x}" + elif pygame.key.get_pressed()[K_s]: + msg = f"{-x}, {-x}" + else: + msg = f"{0}, {0}" + elif event.key == K_s: + msg = f"{0}, {0}" + # print(msg) + elif event.key == K_UP: + msg = f"{0}, {0}" + elif event.key in [K_LEFT, K_RIGHT]: + if pygame.key.get_pressed()[K_UP]: + msg = f"{x}, {x}" + elif pygame.key.get_pressed()[K_DOWN]: + msg = f"{-x}, {-x}" + else: + msg = f"{0}, {0}" + elif event.key == K_DOWN: + msg = f"{0}, {0}" + if msg is not None: + print("Message published in KeyUP ", msg) + result = client.publish(TOPIC, msg) + + if event.type == QUIT: # close the pygame window + running = False + print("Data Collection - Quit 🚪") + sys.exit() + + # Clear the screens + control_display.fill(white) + video_display.fill(white) + display_text() + # Blit the video frame on the video display + video_display.blit(video_frame, (0, 0)) + + # Blit the control and video displays onto the main screen + screen.blit(control_display, (0, 0)) + screen.blit(video_display, (control_width, 0)) + + pygame.display.update() + + # Clean up resources + cv2.destroyAllWindows() + client.disconnect() + #pygame.quit() + sys.exit() + +if __name__ == '__main__': + speed_input() + main() \ No newline at end of file diff --git a/Environment_Setup/mqtt_conf.conf b/Meritus-CVPRO-main/Environment_Setup/mqtt_conf.conf similarity index 100% rename from Environment_Setup/mqtt_conf.conf rename to Meritus-CVPRO-main/Environment_Setup/mqtt_conf.conf diff --git a/Meritus-CVPRO-main/Environment_Setup/requirements.txt b/Meritus-CVPRO-main/Environment_Setup/requirements.txt new file mode 100644 index 0000000..107a1ff --- /dev/null +++ b/Meritus-CVPRO-main/Environment_Setup/requirements.txt @@ -0,0 +1,15 @@ +tqdm~=4.66.1 +numpy~=1.26.0 +pygame~=2.4.0 +pandas~=2.1.1 +pillow~=10.1.0 +seaborn~=0.13.0 +paho-mqtt~=1.6.1 +matplotlib~=3.8.0 +scikit-learn~=1.3.1 +opencv-python~=4.5.4.60 + + + + + diff --git a/Images/app-store-cvpro.png b/Meritus-CVPRO-main/Images/app-store-cvpro.png similarity index 100% rename from Images/app-store-cvpro.png rename to Meritus-CVPRO-main/Images/app-store-cvpro.png diff --git a/Images/cvpro-mecanum.png b/Meritus-CVPRO-main/Images/cvpro-mecanum.png similarity index 100% rename from Images/cvpro-mecanum.png rename to Meritus-CVPRO-main/Images/cvpro-mecanum.png diff --git a/Images/cvpro.png b/Meritus-CVPRO-main/Images/cvpro.png similarity index 100% rename from Images/cvpro.png rename to Meritus-CVPRO-main/Images/cvpro.png diff --git a/Images/play-store-cvpro.png b/Meritus-CVPRO-main/Images/play-store-cvpro.png similarity index 100% rename from Images/play-store-cvpro.png rename to Meritus-CVPRO-main/Images/play-store-cvpro.png diff --git a/Training_Process/Training_Data/Dataset_CVPRO/Autonomous_Driving/.gitkeep b/Meritus-CVPRO-main/Training_Process/Training_Data/Dataset_CVPRO/Autonomous_Driving/gitkeep similarity index 100% rename from Training_Process/Training_Data/Dataset_CVPRO/Autonomous_Driving/.gitkeep rename to Meritus-CVPRO-main/Training_Process/Training_Data/Dataset_CVPRO/Autonomous_Driving/gitkeep diff --git a/Training_Process/Training_Data/Dataset_CVPRO/Image_Classification/.gitkeep b/Meritus-CVPRO-main/Training_Process/Training_Data/Dataset_CVPRO/Image Classification/gitkeep similarity index 100% rename from Training_Process/Training_Data/Dataset_CVPRO/Image_Classification/.gitkeep rename to Meritus-CVPRO-main/Training_Process/Training_Data/Dataset_CVPRO/Image Classification/gitkeep diff --git a/Training_Process/Utils/createdataset.py b/Meritus-CVPRO-main/Training_Process/Utils/createdataset.py similarity index 100% rename from Training_Process/Utils/createdataset.py rename to Meritus-CVPRO-main/Training_Process/Utils/createdataset.py diff --git a/Training_Process/Utils/encoder.py b/Meritus-CVPRO-main/Training_Process/Utils/encoder.py similarity index 100% rename from Training_Process/Utils/encoder.py rename to Meritus-CVPRO-main/Training_Process/Utils/encoder.py diff --git a/Training_Process/Utils/train.py b/Meritus-CVPRO-main/Training_Process/Utils/train.py similarity index 100% rename from Training_Process/Utils/train.py rename to Meritus-CVPRO-main/Training_Process/Utils/train.py diff --git a/Training_Process/main.ipynb b/Meritus-CVPRO-main/Training_Process/main.ipynb similarity index 100% rename from Training_Process/main.ipynb rename to Meritus-CVPRO-main/Training_Process/main.ipynb diff --git a/Training_Process/main.py b/Meritus-CVPRO-main/Training_Process/main.py similarity index 100% rename from Training_Process/main.py rename to Meritus-CVPRO-main/Training_Process/main.py diff --git a/README.md b/README.md index ef836ad..05c8979 100644 --- a/README.md +++ b/README.md @@ -1,362 +1,89 @@ -# CV Pro -

- -

- -CV Pro is a cutting-edge development and education platform with smart computer vision technology. This utilizes the extensive sensor suites, powerful computational abilites and state-of-the-art communication channels. They enable users to learn the intricacies of AI techonlogies such as Machine Learning, Deep Learning, which are utilized in real-time Autonomous Vehicles. - -## Get the source code - -- You can download the repository as a [zip file](https://github.com/robotixdevteam/Meritus-CVPRO/archive/refs/heads/master.zip) and extract it into a folder of your choice. -- You can clone the Meritus-CVPRO repository from GitHub with the following command: - - ```bash - git clone https://github.com/robotixdevteam/Meritus-CVPRO.git - ``` - -## Install the apps - -The easiest way to get either of the apps is to download it directly to the phone using the corresponding QR code. - - - - - - - - - - -
-

- Android 📱 App -

-
-

- iOS 📱 App -

-
Android 📱 AppiOS 📱 App
- - -## You first need to setup your environment. - -## Dependencies - -We recommend to create a conda environment for CVPRO. Instructions on installing conda can be found [here](https://docs.conda.io/projects/conda/en/latest/user-guide/install/). The easiest way to create a new environment with all dependencies is to use one of the provided environment files. On Windows, you will also need to install [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/). Make sure you are in the folder `Environment_Setup` within your local Meritus-CVPRO repository. Based on your operating system, run the corresponding command: - -### Environment Setup - -First create a new conda environment with the following command: - -```bash -conda create -n cvpro python=3.9 -y -``` - -Next, you need to activate your conda environment: - -```bash -conda activate cvpro -``` - -Once your environment is active, install __TensorFlow__. For optimal training speed, especially on dedicated workstations or computers with dedicated GPUs, we recommend installing the necessary libraries and keeping your GPU drivers up to date. See below for TensorFlow installation commands on different Operating Systems. - -#### **Windows** -``` -pip install tensorflow~=2.9.0 -``` - -GPU support -``` -conda install cudatoolkit=11.3 cudnn=8.2 -y -``` - -#### **Linux** -``` -pip install tensorflow~=2.9.0 -``` - -GPU support -``` -sudo apt-get install nvidia-driver-510 -conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1 -y -echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/' >> ~/.bashrc -source ~/.bashrc -``` -[Troubleshooting](https://www.tensorflow.org/install/pip#linux) - -#### **Mac** -``` -conda install -c apple tensorflow-deps -y -pip install tensorflow-macos~=2.9.0 -``` - -GPU support -``` -pip install tensorflow-metal~=0.5.0 -``` -[Troubleshooting](https://developer.apple.com/metal/tensorflow-plugin/) - -#### **Additional Requirements** - -Make sure you are in the folder, `Environment_Setup` within your local Meritus-CVPRO repository. Now, you can install all the remaining dependencies using the following command: - -```bash -pip install -r requirements.txt -``` -### Notes - -- Remember to activate the environment, before running commands in the terminal: `conda activate cvpro` -- If your tensorflow import does not work, try installing via `pip install tensorflow --user`. - -## MQTT - -### Installation of Packages - -Install the Mqtt in your local system. Here, are the step-by-step instructions for downloading mosquitto MQTT Broker: - -1. Click [here](https://mosquitto.org/files/binary/win64/mosquitto-2.0.15-install-windows-x64.exe) for Windows 64-bit OS and [here](https://mosquitto.org/files/binary/win32/mosquitto-2.0.15-install-windows-x86.exe) for Windows 32-bit OS. (Note: Download the version that corresponds to your Windows build). - -2. For macOS, open your terminal and enter the following command to install mosquitto using the homebrew project. - - ```bash - brew install mosquitto - ``` - -3. For Ubuntu-OS, open your terminal and run the following commands: - - ```bash - sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa - sudo apt-get update - ``` - These commands will add the mosquitto repository to your sources list and update your package lists. You can then install mosquitto using the following command: - - ```bash - sudo apt-get install mosquitto - ``` - -***Important Note:*** If you own CV Pro with Mecanum wheels, you are in for an exciting experience. Skip the following sections and simply [click](#Mecanum) to learn how to operate your kit with these innovative wheels. **`The CV Pro Mecanum version can be operated without the need for a smartphone`**. - -# Connection - -## How to Set up the Local Server Connection: - -1. First, disable the Mobile-data and disconnect existing WiFi connections of your phone. Enable the WiFi feature on your computer and ensure that computer is within proximity for better connection. - -2. Turn on the CV Pro bot, that acts as the hotspot and check if unique ID of your bot is displayed in the WiFi connection. Establish connection by entering the `WiFi-Name = 'cvpro' (for example, 'cvpro0123')` and `Wifi-Password = '12345678'`. - -3. Initiating server: - -- For `Windows`, navigate to the folder where the mosquitto package is installed (`C:\ProgramFiles\Mosquitto`). Copy the configuration file, `mqtt_conf.conf` from the `Environment_Setup` folder in local Meritus-CVPRO repository and paste into the Mosquitto installation folder. Open the Command-Prompt/Terminal from this folder. - - - Type or paste following command and your server will start. - - ```bash - mosquitto -v -c .\mqtt_conf.conf - ``` - -- For `Linux/Ubuntu`, you need not navigate to the installed path or copy the configuration file. Just launch the Terminal, - - - command >> cd '_path to the_ **mqtt_conf.conf** _file which is present in downloaded local `Meritus-CVPRO` repository in folder `Environment_Setup`_'. - - - Type or paste following command and your server will start. - - ```bash - mosquitto -v -c mqtt_conf.conf - ``` - -- For `Mac`, you need not navigate to the installed path or copy the configuration file. Just launch the Terminal, - - - command >> cd '_path to the_ **mqtt_conf.conf** _file which is present in downloaded local `Meritus-CVPRO` repository in folder `Environment_Setup`_'. - - - Type or paste following command and your server will start. - - ```bash - mosquitto -v -c mqtt_conf.conf - ``` - -4. Now connect smartphone to the same WiFi name as you connected your computer. - -5. Launch the CV Pro Application and tap on `Settings`:gear: icon, which is on top-right corner of the screen. In the 'Settings' Screen, option displayed, tap on '`Server connection` menu. A new screen will be opened with options to enter `IP Address` and `Name to connect` fields. Enter the IP address, `192.168.4.2` and `cvpro` in Name to connect field. Then click on `Connect` button to connect to the server. - -***Note: If you are unable to establish connection, repeat the steps 1-to-4.*** - -6. To activate your environment, -- For **Windows**, Open the Anaconda Prompt, - - ```bash - conda activate cvpro - ``` - -- For **Linux/Ubuntu**, Open the Terminal, - - ```bash - conda activate cvpro - ``` - -- For **Mac**, Open the Terminal, - - ```bash - conda activate cvpro - ``` - -**Note:** If you receive message `EnvironmentNameNotFound`, after this step, create and activate the environment, by following steps in [Dependencies](#Dependencies). - -# How to use the CV PRO APPLICATION with CV PRO BOT - -## Collect Data - -In order to train the bot, you need to collect a dataset. The more quality data you collect, you get better output. - -1. Press the `Collect Data` button which is in the Home Screen. _Allow the necessary permissions to take pictures and record videos_. - -2. In the Data Collection Screen, verify the _connection status_ (placed at top-left side). If _not connected_, re-connect by following the steps in [server connection](#Connection) section. - -3. When the connection is established with Local Server, check if the Anaconda environment is activated or not in your computer. Verify this, by navigating to your Anaconda Prompt. If environment is inactive, reactivate environment by repeating the sixth (`6th`) step of [server connection](#Connection) section. - -4. Check the Anaconda Prompt, whether you are in the path of `Controller` in Local `Meritus-CVPRO` Repository. If not, change the path in Anaconda Prompt using this command, - -- command >> cd '_path to the python file which is present in downloaded local `Meritus-CVPRO` repository in folder `Controller`_'. - -- Type or paste the following command in Anaconda Prompt, for _only Data Collection and bot control_ use this command. - - ```bash - python control_bot.py - ``` - -- Type or paste the following command in Anaconda Prompt, for _Data Collection with video-stream and bot control_ use this command. - - ```bash - python videostream_control_bot.py - ``` - -5. Place the bot on the track and now you can control the bot as well as collect the data based on the controls keys which will be displayed after running the above python command. - -6. After completing the data collection process, close the 'CV PRO Application' on your smartphone. Disconnect the connection between the devices by closing the server connection on the computer, using '_ctrl+c_' or '_command+c_,' or clicking the 'X' in the Command Prompt or Terminal from where you are running the server connection. - -7. Copy the collected data from the folder `CVPRO` in your smartphone to your computer. Open the local `Meritus-CVPRO` repository and go to the location -> `Training_Process\Training_Data\Dataset_CVPRO\` and place it in `Autonomous_Driving` folder to enable the movement of bot in _autonomous mode_. For the image classification, place the data collected in, `Image_Classification` folder to _classify the images_. - -**Note: Avoid pasting the compressed files directly. Make sure to extract the files first.** - -## Training Process - -Make sure your conda environment for CVPRO is activated by executing the following command: - -```bash -conda activate cvpro -``` - -The training process can be visualised either in Python script or in jupyter notebook: - -- To start in the Python script, navigate to the folder, `Training_Process` within your local `Meritus-CVPRO` repository. Type or paste the following command in Anaconda Prompt, - -```bash -python main.py -``` - -- To visualize the same using Jupyter notebook, you can use jupyter notebook file "**main.ipynb**". Type or paste the following command in Anaconda Prompt, - -```bash -jupyter notebook main.ipynb -``` - -After training process is complete, the script will generate three files (_best.tflite, last.tflite and label.txt_). The files are saved in the location `Training_Process -> Training_Data -> Save_Model`. - -Copy/Move the above three files from computer to smartphone to the folder of your choice. - -## Model Management - -To upload the model, Open the _CV PRO_ Application in your smartphone and go to `Settings`:gear: icon. Tap on the `Model management` section and click the `upload file` button, select the "***best.tflite*** or ***last.tflite***" from the saved location. - -After the file is uploaded, a menu will appear at the bottom of the screen. From there, you can _change the model's name_ and choose the category in which you want to place the model, from the list of categories displayed. To upload the `label.txt` text file, simply tap on the :paperclip: icon and tap on `Submit` button. - -Go to home Screen in _CV PRO_ Application, choose an option among the menu, -- Click the **Autonomous Driving** to run on autonomous mode. -- Click the **Image Classification** to classify the image. -- Click the **Object Detection** to follow an object from the list of objects. - - -# Mecanum -

- -

- -# CV Pro with Mecanum Wheels - -CV Pro is now equipped with the new feature: **`Mecanum wheels`**. Swap the existing wheels with the Mecanum wheels provided. These omnidirectional wheels can move in any direction, offering incredible maneuverability. - -## Connection - -## How to Setup the Local Server Connection -1. Ensure that computer is within proximity and turn-on the CV Pro bot, that acts as the hotspot and check if unique ID of your bot is displayed in the WiFi connection. Establish connection by entering the `WiFi-Name = 'cvpro' (for example, 'cvpro0123')` and `Wifi-Password = '12345678'`. - -2. Initiating server: - -- For `Windows`, navigate to the folder where the mosquitto package is installed (`C:\ProgramFiles\Mosquitto`). Copy the configuration file, `mqtt_conf.conf` from the `Environment_Setup` folder in local Meritus-CVPRO repository and paste into the Mosquitto installation folder. Open the Command-Prompt/Terminal from this folder. - - - Type or paste following command and your server will start. - - ```bash - mosquitto -v -c .\mqtt_conf.conf - ``` - -- For `Linux/Ubuntu`, you need not navigate to the installed path or copy the configuration file. Just launch the Terminal, - - - command >> cd '_path to the_ **mqtt_conf.conf** _file which is present in downloaded local `Meritus-CVPRO` repository in folder `Environment_Setup`_'. - - - Type or paste following command and your server will start. - - ```bash - mosquitto -v -c mqtt_conf.conf - ``` - -- For `Mac`, you need not navigate to the installed path or copy the configuration file. Just launch the Terminal, - - - command >> cd '_path to the_ **mqtt_conf.conf** _file which is present in downloaded local `Meritus-CVPRO` repository in folder `Environment_Setup`_'. - - - Type or paste following command and your server will start. - - ```bash - mosquitto -v -c mqtt_conf.conf - ``` - -3. Navigate to the `...\Meritus-CVPRO-main\Controller` directory, from your Anaconda prompt. - -4. To activate your environment, -- For **Windows**, Open the Anaconda Prompt, - - ```bash - conda activate cvpro - ``` - -- For **Linux/Ubuntu**, Open the Terminal, - - ```bash - conda activate cvpro - ``` - -- For **Mac**, Open the Terminal, - - ```bash - conda activate cvpro - ``` -**Note:** If you receive message `EnvironmentNameNotFound`, after this step, create and activate the environment, by following steps in [Dependencies](#Dependencies). - -5. In Anaconda prompt, run the following command to set your kit in motion: - - ```bash - python mecanum_control_bot.py - ``` - -6. A pygame controller window will appear on your computer screen, allowing you to control your robot using the key combinations provided. Observe your kit's smooth, multidirectional movement. - -With CV Pro's new Mecanum wheels, you have expanded possibilities for hands-on learning. - - -## Contact - -- Contact us via [Email](mailto:development@merituseducation.com) - - - - - +# Meritus-CVPRO +## CV_PRO – STANDARD OPERATING PROCEDURE + +### Agenda: + +- Git-hub Repository. +- Downloading and Installation of Sources. +- Extraction to Root Directory. +- Terminal Execution. + +### GitHub Repository: +- Go to https://github.com/robotixdevteam/Meritus-CVPRO/tree/Windows. +- Download the ZIP file. + +### Downloading and Installation of Sources: +#### Download and install the Miniconda in the User Profile Path. +- We recommend to create a conda environment for CVPRO. Instructions on installing conda can be found [here](https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe). +- The easiest way to create a new environment with all dependencies is to use one of the provided environment files. + +#### Download and Install the Ecllipse-Mosquitto in C:\Program Files. + +- Install the Mqtt in your local system. Here, are the step-by-step instructions for downloading mosquitto MQTT Broker: +- Click [here](https://mosquitto.org/files/binary/win64/mosquitto-2.0.15-install-windows-x64.exe) for Windows 64-bit OS and [here](https://mosquitto.org/files/binary/win32/mosquitto-2.0.15-install-windows-x86.exe) for Windows 32-bit OS. (Note: Download the version that corresponds to your Windows build). + + +### Extraction to Root Directory: + +- Extract the ZIP to User Profile Path. + + +### Terminal Execution: + +#### Step 1: Execute ‘cvpro’ + +- Windows: + - Open the Meritus-CVPRO-Windows (Extracted) and open the path in Windows-Command-Prompt, by typing ‘cmd’ in the Address Bar or Breadcrumb Bar. Or, Press ‘Win + R’ which opens the "Run" dialog, then type ‘cmd’ and press ‘Enter’. Now execute the command as follows: +cd Meritus-CVPRO-Windows + - Execute the command ‘cvpro’. This is your main or Working-Terminal. + - Follow the instructions as per the execution. + - Create and Activate the Environment. + - Installation of Dependencies + - Launch the Server + - ‘Run’ or ‘Train’ the Bot. + +#### Step 2: Conda Environment Setup: +- Type ‘my_conda’, and press ‘Enter’. This will prompt you for further options – ‘build’, ‘activate’ or ‘deactivate’. +- Choose and type the required option as follows: + - Choose and Type ‘build’ and press ‘Enter’. This will create and activate a new conda-environment in the name cvpro. Once after execution, the guide for installation of python libraries will be displayed. + - Choose and Type ‘activate’ and press ‘Enter’ only if you have already built the cvpro environment and installed all the required python libraries in it. That is, the second time when you are integrating or erecting the kit. This will activate the conda environment (cvpro) which is already created and gives the guide for launching the MQTT Server and Data Collection Process/Training Process. + - Choose and Type ‘deactivate’ and press ‘Enter’, only if you have already built the cvpro environment and also when required. This will deactivate the active environment and bring it to (base). + + +#### Step 3: Installation of Python Libraries: +- After building the conda environment, the next step is to install the python libraries, by inputting the command, ‘install_cvpro’ +- This will prompt you for internet connection check. +- This includes upgradation of pip, tensorflow installation, and required python libraries for data collection and training processes. +- After completing the installation, the guide for data collection process or training process will be displayed. + + +#### Step 4: MQTT Server: + +- Post installation, read the instructions carefully (displayed in the terminal window) before entering the command ‘launch_server’ +- This command will open/launch the MQTT Server in a separate terminal. +- Minimize or keep this terminal aside, as this is not the working / main terminal for data collection or training process. + +#### Step 5: Data Collection Process: + +- The Data Collection Process should be carried out in Working Terminal, by entering the command ‘run_cvpro’. This will take the user into following three prompts one after the other: + - Two further options upon execution of ‘run_cvpro’ – ‘control’ or ‘videostream’. + - Prompt for connecting the bot with the application will be displayed. + - Prompt for speed input for the kit. The user can choose any range between the specified (170-255). The value ‘220’ is more optimal. +- Please make a note that, the terminal clears or refreshes the session, while executing the ‘run_cvpro’. + +#### Step 6: Training Process: + +- The Training Process should be carried out in Working Terminal, by entering the command ‘train_cvpro’. This will take the user into following five prompts one after the other: + - Prompt for disconnecting the bot from the application as well as system, will be displayed. + - Prompt for Batch Size required for the Training Process. The preset value will be automatically entered if you directly press ‘Enter’ without giving any input value. + - Prompt for Epoch Value required for the Training Process. The preset value will be automatically entered if you directly press ‘Enter’ without giving any input value. + - Prompt for Learning Rate required for the Training Process. The preset value will be automatically entered if you directly press ‘Enter’ without giving any input value. + - Prompt for ‘User Password’ required for the permanently deleting the garbage files, that are not required for the Training Process. +- Please make a note that, the terminal clears or refreshes the session, while executing the ‘train_cvpro’. + + +## Important Notes +The user who has downloaded the Updated CVPRO ZIP from GitHub, and is following the same, Please Ensure the following before implementing the process: +- Delete the Meritus-CVPRO-Windows folder (Any Folder with Identical Name) in the User Profile Path, if exists. +- Re-Install the miniconda, (if it already exists and ensure that the entire miniconda3 folder is deleted and newly created in the user profile path while re-installing).  +- Begining the process from my_conda -> build, and not my_conda -> activate.  ('my_conda -> activate' should be used only from the second time onwards). diff --git a/cvpro.cmd b/cvpro.cmd new file mode 100644 index 0000000..080c900 --- /dev/null +++ b/cvpro.cmd @@ -0,0 +1,34 @@ +@echo off +set "userProfile=%USERPROFILE%" +set mosquittoProfile= C:\Program Files + +echo. +echo Pre-Requisites: +echo --------------- +echo 1. Download the Meritus-CVPRO from https://github.com/robotixdevteam/Meritus-CVPRO/tree/Windows and extract the same to the User-Profile Path +echo. +echo 2. Miniconda should be installed in the User-Profile Path +echo. +echo 3. Mosquitto should be installed in %mosquittoProfile% +echo. + +echo Hierarchy of Execution: +echo ----------------------- +echo Type 'my_conda' - Create or Activate the Conda Environment +echo. +echo Type 'install_cvpro' - Installation of required libraries +echo. +echo -------------------------------------------------------------------- +echo Please ensure to connect the Bot with the System +echo Type 'launch_server' - Launch the MQTT Server +echo -------------------------------------------------------------------- +echo. +echo Type 'run_cvpro' to move the Bot around for Data-Collection Process. +echo. +echo Type 'train_cvpro' to train the Bot for Autonomous Process. + +doskey my_conda="%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Controller\activate_cvpro.bat" +doskey install_cvpro="%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Controller\install.bat" +doskey launch_server=start cmd /K "%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Controller\launch_mosquitto.bat" +doskey run_cvpro="%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Controller\test_run.bat" +doskey train_cvpro="%userProfile%\Meritus-CVPRO-Windows\Meritus-CVPRO-main\Controller\train.bat" \ No newline at end of file