Difference between revisions of "2021SummerTeam6"
Jump to navigation
Jump to search
Line 38: | Line 38: | ||
= '''Final Project Overview''' = | = '''Final Project Overview''' = | ||
= | ==YoloV5 Object Detection Code == | ||
<nowiki> | |||
import rospy | |||
import cv2 | |||
import numpy as np | |||
from std_msgs.msg import Int32, Int32MultiArray | |||
from sensor_msgs.msg import Image | |||
from decoder import decodeImage | |||
import time | |||
from cv_bridge import CvBridge | |||
from elements.yolo import OBJ_DETECTION | |||
# Give names for nodes and topics for ROS | |||
STOPSIGN_NODE_NAME = 'stopsign_node' | |||
STOPSIGN_TOPIC_NAME = 'StopSign' | |||
CAMERA_TOPIC_NAME = 'camera_rgb' | |||
# | # types of objects that can be detected | ||
Object_classes = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush' ] | |||
Object_colors = list(np.random.rand(80,3)*255) | |||
Object_detector = OBJ_DETECTION('weights/yolov5s.pt', Object_classes) | |||
## | class StopSignDetection: | ||
# | def __init__(self): | ||
self.init_node = rospy.init_node(STOPSIGN_NODE_NAME, anonymous=False) # initialize the node | |||
self.StopSign_publisher = rospy.Publisher(STOPSIGN_TOPIC_NAME,Int32, queue_size=1) # make this node a publisher | |||
self.camera_subscriber = rospy.Subscriber(CAMERA_TOPIC_NAME,Image,self.detect_stop) # subscribe to the camera feed | |||
self.bridge =CvBridge() | |||
self.stopsign = Int32() | |||
def detect_stop(self,data): | |||
frame = self.bridge.imgmsg_to_cv2(data) # get frame from camera feed data | |||
# | # detection process | ||
objs = Object_detector.detect(frame) # detect the object | |||
# plotting | |||
for obj in objs: | |||
# print(obj) | |||
label = obj['label'] | |||
score = obj['score'] | |||
[(xmin,ymin),(xmax,ymax)] = obj['bbox'] | |||
color = Object_colors[Object_classes.index(label)] | |||
frame = cv2.rectangle(frame, (xmin,ymin), (xmax,ymax), color, 2) | |||
frame = cv2.putText(frame, f'{label} ({str(score)})', (xmin,ymin), | |||
cv2.FONT_HERSHEY_SIMPLEX , 0.75, color, 1, cv2.LINE_AA) | |||
cv2.imshow('stopsign',frame) # create window to show objects detected | |||
cv2.waitKey(1) | |||
# if a stop sign is detected send out a 1 else send out 0 | |||
if label == 'stop sign' and score > 0.1: | |||
self.stopsign.data = 1 | |||
self.StopSign_publisher.publish(self.stopsign) | |||
else: | |||
self.stopsign.data = 0 | |||
self.StopSign_publisher.publish(self.stopsign) | |||
def main(): | |||
StopSign_detector = StopSignDetection() | |||
rate = rospy.Rate(15) | |||
while not rospy.is_shutdown(): | |||
rospy.spin() | |||
rate.sleep() | |||
if __name__=='__main__': | |||
main() | |||
</nowiki> | |||
Revision as of 00:49, 6 September 2021
Team 6 Members
From Left to Right
Kevin Bishara (MAE) | William Lynch (ECE) | Anwar Hsu (ECE)
Robot & 3D Modeling Designs
Our Robot
Electronics Plate
Camera Mount
Jetson Nano Case
Autonomous Laps
DonkeyCar Laps
Our autonomous laps for DonkeyCar can be found here.
OpenCV/ROS Laps
Our OpenCV/ROS autonomous laps can be found here.
Final Project Overview
YoloV5 Object Detection Code
import rospy import cv2 import numpy as np from std_msgs.msg import Int32, Int32MultiArray from sensor_msgs.msg import Image from decoder import decodeImage import time from cv_bridge import CvBridge from elements.yolo import OBJ_DETECTION # Give names for nodes and topics for ROS STOPSIGN_NODE_NAME = 'stopsign_node' STOPSIGN_TOPIC_NAME = 'StopSign' CAMERA_TOPIC_NAME = 'camera_rgb' # types of objects that can be detected Object_classes = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush' ] Object_colors = list(np.random.rand(80,3)*255) Object_detector = OBJ_DETECTION('weights/yolov5s.pt', Object_classes) class StopSignDetection: def __init__(self): self.init_node = rospy.init_node(STOPSIGN_NODE_NAME, anonymous=False) # initialize the node self.StopSign_publisher = rospy.Publisher(STOPSIGN_TOPIC_NAME,Int32, queue_size=1) # make this node a publisher self.camera_subscriber = rospy.Subscriber(CAMERA_TOPIC_NAME,Image,self.detect_stop) # subscribe to the camera feed self.bridge =CvBridge() self.stopsign = Int32() def detect_stop(self,data): frame = self.bridge.imgmsg_to_cv2(data) # get frame from camera feed data # detection process objs = Object_detector.detect(frame) # detect the object # plotting for obj in objs: # print(obj) label = obj['label'] score = obj['score'] [(xmin,ymin),(xmax,ymax)] = obj['bbox'] color = Object_colors[Object_classes.index(label)] frame = cv2.rectangle(frame, (xmin,ymin), (xmax,ymax), color, 2) frame = cv2.putText(frame, f'{label} ({str(score)})', (xmin,ymin), cv2.FONT_HERSHEY_SIMPLEX , 0.75, color, 1, cv2.LINE_AA) cv2.imshow('stopsign',frame) # create window to show objects detected cv2.waitKey(1) # if a stop sign is detected send out a 1 else send out 0 if label == 'stop sign' and score > 0.1: self.stopsign.data = 1 self.StopSign_publisher.publish(self.stopsign) else: self.stopsign.data = 0 self.StopSign_publisher.publish(self.stopsign) def main(): StopSign_detector = StopSignDetection() rate = rospy.Rate(15) while not rospy.is_shutdown(): rospy.spin() rate.sleep() if __name__=='__main__': main()