Difference between revisions of "2021SummerTeam6"

From MAE/ECE 148 - Introduction to Autonomous Vehicles
Jump to: navigation, search
(Our Python Code!)
(Our Python Code!)
Line 39: Line 39:
 
      
 
      
 
= '''Our Python Code!''' =
 
= '''Our Python Code!''' =
  <nowiki># -*- coding: utf-8 -*-
+
  <nowiki>
"""
+
import rospy
Created on Mon Mar 29 14:31:14 2021
+
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
  
@author: Anwar
+
# Give names for nodes and topics for ROS
"""
+
STOPSIGN_NODE_NAME = 'stopsign_node'
## You need to install pyaudio to run this example
+
STOPSIGN_TOPIC_NAME = 'StopSign'
# pip install pyaudio
+
CAMERA_TOPIC_NAME = 'camera_rgb'
  
# When using a microphone, the AudioSource `input` parameter would be
+
# types of objects that can be detected
# initialised as a queue. The pyaudio stream would be continuosly adding
+
 
# recordings to the queue, and the websocket client would be sending the
+
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' ]
# recordings to the speech to text service
+
 
 +
 
 +
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, co

Revision as of 16:47, 5 September 2021

Team 6 Members

P1.jpg


From Left to Right

Kevin Bishara (MAE) | William Lynch (ECE) | Anwar Hsu (ECE)

Robot & 3D Modeling Designs

Our Robot

P2.png

Electronics Plate

Cad1.png

Camera Mount

Jetson Nano Case

Cad2.png Cad3.png

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

Our Python 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

  1. Give names for nodes and topics for ROS

STOPSIGN_NODE_NAME = 'stopsign_node' STOPSIGN_TOPIC_NAME = 'StopSign' CAMERA_TOPIC_NAME = 'camera_rgb'

  1. 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, co