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
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 __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 __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 __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 __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 rank_image_cb(self, msg): logger.info( 'Received message with {} compressed_imgs, {} imgs, {} strs'. format(len(msg.compressed_imgs), len(msg.imgs), len(msg.strs))) if self.trial and not self.trial.mode in (Trial.State.ABORTED, Trial.State.COMPLETED): print('Aborting due to ongoing trial') self.action_server.set_aborted() return self.reset() if len(msg.compressed_imgs) > 0: self.screen.fill((255, 255, 255)) self.screen.blit( self.font.render( 'Received {} images'.format(len(msg.compressed_imgs)), 1, (0, 0, 0)), (40, self.size[1] / 2)) pygame.display.flip() scaled_imgs = [ ImageConverter.from_ros(img) for img in msg.compressed_imgs ] self.start_trial( Trial(zip(msg.option_ids, scaled_imgs), size=self.size, preview_time=4000, image_time=self.PRESENTATION_DELAY)) while self.ranking: pygame.time.wait(100) else: self.action_server.set_aborted()
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
def keyboard_rank_cb(self, msg): rospy.loginfo("received msg") self.screen.fill((0,0,0)) scaled_imgs = [ImageConverter.from_ros(img) for img in msg.compressed_imgs] self.options = zip(msg.option_ids, scaled_imgs) elements_per_side = int(math.ceil(math.sqrt(len(self.options)))) grid_w = self.size[0] / elements_per_side grid_h = self.size[1] / elements_per_side counter = 0 for idx in range(len(self.options)): row = counter / elements_per_side col = counter % elements_per_side rect = pygame.Rect((row * grid_w, col * grid_h), (grid_w, grid_h)) subsurf = self.screen.subsurface(rect) subsurf.blit(pygame.transform.smoothscale(self.options[idx][1], (grid_w, grid_h)), (0, 0)) counter += 1 pygame.display.flip() while self.options and self.running: pygame.time.wait(100)
def rank_image_cb(self, msg): logger.info( 'Received message with {} compressed_imgs, {} imgs, {} strs'.format(len(msg.compressed_imgs), len(msg.imgs), len(msg.strs))) if self.trial and not self.trial.mode in (Trial.State.ABORTED, Trial.State.COMPLETED): print('Aborting due to ongoing trial') self.action_server.set_aborted() return self.reset() if len(msg.compressed_imgs) > 0: self.screen.fill((255, 255, 255)) self.screen.blit(self.font.render( 'Received {} images'.format(len(msg.compressed_imgs)), 1, (0, 0, 0)), (40, self.size[1] / 2)) pygame.display.flip() scaled_imgs = [ImageConverter.from_ros(img) for img in msg.compressed_imgs] self.start_trial(Trial(zip(msg.option_ids, scaled_imgs), size=self.size, preview_time=4000, image_time=self.PRESENTATION_DELAY)) while self.ranking: pygame.time.wait(100) else: self.action_server.set_aborted()
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
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
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
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()
def twitch_smile_resizer(): if request.method == 'GET': return send_from_directory(directory='./', filename='index.html') if 'file' not in request.files: flash('No file part') return jsonify({"error": "please add square image file"}) if request.method == 'POST': # check if the post request has the file part file = request.files['file'] filename = file.filename if file.filename == '': flash('No selected file') return jsonify({"error": "please add square image file"}) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) resample_type = request.form['resample'] converted_images_name = ImageConverter().convert_image_to_twitch_format(secure_filename(file.filename), resample=resample_type) if not converted_images_name: os.remove(file.filename) return jsonify({"error": "please add square image file"}) os.remove(file.filename) return send_file(os.path.join('zip_files', converted_images_name), as_attachment=True)
def handle_dot_file(self, current_cmd): the_image_converter = ImageConverter() the_image_converter.produce_image_b()
import sys from file_manager import FileManager from image_converter import ImageConverter print("Start image converter") source_path = sys.argv[1] target_path = sys.argv[2] size = int(sys.argv[3]) print("Source path:" + source_path + " Target path: "+target_path+" Size: "+ str(size)) manager = FileManager(source_path, target_path) converter = ImageConverter(size) if(manager.is_source_exists()): if(not manager.is_target_exists()): manager.create_target() print("Target created") for image in manager.get_all_images(): img = converter.open_image(image.full_path) converter.resize(img) manager.save_image(img, image) else: print("Source not exists") print("End image converter")
import os import rospy import datetime import time import numpy as np from geometry_msgs.msg import Vector3 from sensor_msgs.msg import Image from image_converter import ImageConverter from std_msgs.msg import String xMin = 0 yMin = 0 xMax = 640 yMax = 310 vehicle_steer = 0 ic = ImageConverter() path = '/home/yadav/New_Data_collection/' + str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + '/') if os.path.exists(path + 'stacked_only'): print('path exists. continuing...') else: os.makedirs(path + 'stacked_only') stacked_only_text = open(str(path) + 'stacked_only/' + str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")) + ".txt", "w+") def callback(value): global vehicle_steer #vehicle_vel = value.linear.x vehicle_steer = value.y def recorder1(data):
def converter(): return ImageConverter(SOURCE, TARGET)
def src_converter(): return ImageConverter(SOURCE)