Exemplo n.º 1
0
class NeuralControl:
    def __init__(self):
        rospy.init_node('BMW_controller')
        self.rate = rospy.Rate(10)
        self.ic = ImageConverter()
        self.image_process = ImageProcess()
        self.drive = DriveRun(sys.argv[1])

        rospy.Subscriber('/image_topic_2', Image, self.controller_cb)
        rospy.Subscriber('/usb_cam/image_raw', Image, self.recorder1)
        self.image = None
        self.image_processed = False

    def recorder1(self, image):
        cam_img = self.ic.imgmsg_to_opencv(image)
        cropImg = cam_img[yMin:yMax, xMin:xMax]
        global newimg
        newimg = cv2.resize(cropImg, (160, 50))

    def controller_cb(self, image):
        img = self.ic.imgmsg_to_opencv(image)
        img_resize = cv2.resize(img, (160, 50))
        stacked_img = np.concatenate((img_resize, newimg), axis=0)

        self.image = self.image_process.process(stacked_img)
        self.image_processed = True
Exemplo n.º 2
0
class NeuralControl:
    def __init__(self):
        rospy.init_node('controller')
        self.ic = ImageConverter()
        self.image_process = ImageProcess()
        self.rate = rospy.Rate(30)
        self.drive = DriveRun(sys.argv[1])
        rospy.Subscriber('/bolt/front_camera/image_raw', Image,
                         self.controller_cb)
        self.image = None
        self.image_processed = False
        self.config = Config()

    def controller_cb(self, image):
        img = self.ic.imgmsg_to_opencv(image)
        cropImg = img[self.config.capture_area[1]:self.config.capture_area[3],
                      self.config.capture_area[0]:self.config.capture_area[2]]
        #cropImg = img[yMin:yMax,xMin:xMax]
        img = cv2.resize(
            cropImg, (self.config.image_size[0], self.config.image_size[1]))
        self.image = self.image_process.process(img)

        if self.config.typeofModel == 4 or self.config.typeofModel == 5:
            self.image = np.array(self.image).reshape(
                1, self.config.image_size[1], self.config.image_size[0],
                self.config.image_size[2])
        self.image_processed = True
Exemplo n.º 3
0
class camera:
    def __init__(self):
        self.ic = ImageConverter()
        self.image_process = ImageProcess()
        self.driveC = DriveRun(sys.argv[2])
        rospy.Subscriber('/usb_cam/image_raw', Image, self.recorder1)
        self.imageC = None
        self.camera_processed = False

    def recorder1(self, image):
        cam_img = self.ic.imgmsg_to_opencv(image)
        cropImg = cam_img[yMin:yMax, xMin:xMax]
        self.imageC = cv2.resize(cropImg, (160, 70))
        self.camera_processed = True
Exemplo n.º 4
0
class NeuralControl:
    def __init__(self):
        rospy.init_node('BMW_controller')
        self.ic = ImageConverter()
        self.image_process = ImageProcess()
        self.rate = rospy.Rate(10)
        self.drive= DriveRun(sys.argv[1])
        rospy.Subscriber('/image_topic_2', Image, self.controller_cb)
        self.image = None
        self.image_processed = False

    def controller_cb(self, image): 
        img = self.ic.imgmsg_to_opencv(image)
        img = cv2.resize(img,(160,70))
        self.image = self.image_process.process(img)
        self.image_processed = True
Exemplo n.º 5
0
class NeuralControl:
    def __init__(self):
        rospy.init_node('controller')
        self.ic = ImageConverter()
        self.image_process = ImageProcess()
        self.rate = rospy.Rate(10)
        self.drive= DriveRun(sys.argv[1])
        rospy.Subscriber('/bulldogbolt/camera_left/image_raw_left', Image, self.controller_cb)
        self.image = None
        self.image_processed = False

    def controller_cb(self, image): 
        img = self.ic.imgmsg_to_opencv(image)
	cropImg = img[yMin:yMax,xMin:xMax]
        img = cv2.resize(cropImg,(160,70))
        self.image = self.image_process.process(img)
        self.image_processed = True
Exemplo n.º 6
0
class NeuralControl:
    def __init__(self, weight_file_name):
        rospy.init_node('run_neural')
        self.ic = ImageConverter()
        self.image_process = ImageProcess()
        self.rate = rospy.Rate(30)
        self.drive = DriveRun(weight_file_name)
        rospy.Subscriber(Config.data_collection['camera_image_topic'], Image,
                         self._controller_cb)
        self.image = None
        self.image_processed = False
        #self.config = Config()
        self.braking = False

    def _controller_cb(self, image):
        img = self.ic.imgmsg_to_opencv(image)
        cropped = img[Config.data_collection['image_crop_y1']:Config.
                      data_collection['image_crop_y2'],
                      Config.data_collection['image_crop_x1']:Config.
                      data_collection['image_crop_x2']]

        img = cv2.resize(
            cropped,
            (config['input_image_width'], config['input_image_height']))

        self.image = self.image_process.process(img)

        ## this is for CNN-LSTM net models
        if config['lstm'] is True:
            self.image = np.array(self.image).reshape(
                1, config['input_image_height'], config['input_image_width'],
                config['input_image_depth'])
        self.image_processed = True

    def _timer_cb(self):
        self.braking = False

    def apply_brake(self):
        self.braking = True
        timer = threading.Timer(Config.run_neural['brake_apply_sec'],
                                self._timer_cb)
        timer.start()