Skip to content

Commit b31f8d5

Browse files
author
AdamMiltonBarker
committed
Added RPI4 project and documentation
1 parent 46bd025 commit b31f8d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6927
-4
lines changed

Projects/RPI4/Classes/Helpers.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
############################################################################################
2+
#
3+
# Project: Peter Moss COVID-19 AI Research Project
4+
# Repository: EMAR Mini, Emergency Assistance Robot
5+
#
6+
# Author: Adam Milton-Barker (AdamMiltonBarker.com)
7+
# Contributors:
8+
# Title: Helper Class
9+
# Description: Helper functions for the EMAR Mini, Emergency Assistance Robot.
10+
# License: MIT License
11+
# Last Modified: 2020-04-17
12+
#
13+
############################################################################################
14+
15+
import logging, json, sys, time
16+
import logging.handlers as handlers
17+
18+
from datetime import datetime
19+
20+
21+
class Helpers():
22+
""" Helper Class
23+
24+
Helper functions for the EMAR Mini, Emergency Assistance Robot.
25+
"""
26+
27+
def __init__(self, ltype, log=True):
28+
""" Initializes the Helpers Class. """
29+
30+
# Loads system configs
31+
self.confs = {}
32+
self.loadConfs()
33+
34+
# Sets system logging
35+
self.logger = logging.getLogger(ltype)
36+
self.logger.setLevel(logging.INFO)
37+
38+
formatter = logging.Formatter(
39+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
40+
41+
allLogHandler = handlers.TimedRotatingFileHandler(
42+
'Logs/all.log', when='H', interval=1, backupCount=0)
43+
allLogHandler.setLevel(logging.INFO)
44+
allLogHandler.setFormatter(formatter)
45+
46+
errorLogHandler = handlers.TimedRotatingFileHandler(
47+
'Logs/error.log', when='H', interval=1, backupCount=0)
48+
errorLogHandler.setLevel(logging.ERROR)
49+
errorLogHandler.setFormatter(formatter)
50+
51+
warningLogHandler = handlers.TimedRotatingFileHandler(
52+
'Logs/warning.log', when='H', interval=1, backupCount=0)
53+
warningLogHandler.setLevel(logging.WARNING)
54+
warningLogHandler.setFormatter(formatter)
55+
56+
consoleHandler = logging.StreamHandler(sys.stdout)
57+
consoleHandler.setFormatter(formatter)
58+
59+
self.logger.addHandler(allLogHandler)
60+
self.logger.addHandler(errorLogHandler)
61+
self.logger.addHandler(warningLogHandler)
62+
self.logger.addHandler(consoleHandler)
63+
64+
if log is True:
65+
self.logger.info("Helpers class initialization complete.")
66+
67+
def loadConfs(self):
68+
""" Load the program configuration. """
69+
70+
with open('confs.json') as confs:
71+
self.confs = json.loads(confs.read())

Projects/RPI4/Classes/Model.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
############################################################################################
2+
#
3+
# Project: Peter Moss COVID-19 AI Research Project
4+
# Repository: EMAR Mini, Emergency Assistance Robot
5+
#
6+
# Author: Adam Milton-Barker (AdamMiltonBarker.com)
7+
# Contributors:
8+
# Title: EMAR Mini Model Class
9+
# Description: Model functions for EMAR Mini Emergency Assistance Robot.
10+
# License: MIT License
11+
# Last Modified: 2020-07-12
12+
#
13+
############################################################################################
14+
15+
import cv2
16+
17+
from Classes.Helpers import Helpers
18+
19+
class Model():
20+
""" Model Class
21+
22+
Model helper class for the Paper 1 Evaluation.
23+
"""
24+
25+
def __init__(self):
26+
""" Initializes the Model class. """
27+
28+
self.Helpers = Helpers("Model", False)
29+
30+
self.net = cv2.dnn.readNet(self.Helpers.confs["MobileNetSSD"]["xml"], self.Helpers.confs["MobileNetSSD"]["bin"])
31+
self.net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
32+
33+
self.imsize = self.Helpers.confs["MobileNetSSD"]["size"]
34+
35+
self.Helpers.logger.info("Model class initialization complete.")
36+
37+
def getDims(self, frame):
38+
""" Gets the width and height of frame """
39+
40+
height = frame.shape[0]
41+
width = frame.shape[1]
42+
43+
return width, height
44+
45+
def setBlob(self, frame):
46+
""" Gets a blob from the color frame """
47+
48+
blob = cv2.dnn.blobFromImage(frame, self.Helpers.confs["MobileNetSSD"]["inScaleFactor"],
49+
size=(self.imsize, self.imsize),
50+
mean=(self.Helpers.confs["MobileNetSSD"]["meanVal"],
51+
self.Helpers.confs["MobileNetSSD"]["meanVal"],
52+
self.Helpers.confs["MobileNetSSD"]["meanVal"]),
53+
swapRB=False, crop=False)
54+
55+
self.net.setInput(blob)
56+
57+
def getCrop(self, width, height):
58+
""" Gets the crop size """
59+
60+
ratio = self.imsize / float(self.imsize)
61+
62+
if width / float(height) > ratio:
63+
crop = (int(height * ratio), height)
64+
else:
65+
crop = (width, int(width / ratio))
66+
67+
return crop
68+
69+
def forwardPass(self):
70+
""" Gets a blob from the color frame """
71+
72+
out = self.net.forward()
73+
74+
return out

Projects/RPI4/Classes/Realsense.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
############################################################################################
2+
#
3+
# Project: Peter Moss COVID-19 AI Research Project
4+
# Repository: EMAR Mini, Emergency Assistance Robot
5+
#
6+
# Author: Adam Milton-Barker (AdamMiltonBarker.com)
7+
# Contributors:
8+
# Title: EMAR Mini Realsense D415 Class
9+
# Description: Realsense D415 functions for EMAR Mini Emergency Assistance Robot.
10+
# License: MIT License
11+
# Last Modified: 2020-05-26
12+
#
13+
############################################################################################
14+
15+
import pyrealsense2 as rs
16+
17+
from Classes.Helpers import Helpers
18+
19+
class Realsense():
20+
21+
def __init__(self):
22+
""" Realsense D415 Class
23+
24+
Realsense D415 functions for the EMAR Mini Emergency Assistance Robot.
25+
"""
26+
27+
self.Helpers = Helpers("Realsense D415", False)
28+
self.Helpers.logger.info("Realsense D415 Helper Class initialization complete.")
29+
30+
def connect(self):
31+
""" Connects to the Realsense D415 camera. """
32+
33+
self.pipeline = rs.pipeline()
34+
35+
config = rs.config()
36+
#config.enable_stream(rs.stream.infrared, 1, 640, 480, rs.format.y8, 30)
37+
#config.enable_stream(rs.stream.infrared, 2, 640, 480, rs.format.y8, 30)
38+
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
39+
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
40+
41+
prof = self.pipeline.start(config)
42+
43+
self.Helpers.logger.info("Connected To Realsense D415")
44+
45+
return prof

0 commit comments

Comments
 (0)