Пример #1
0
def main():

    if (len(sys.argv) != 2):
        print('Give the model path.')
        return

    drive = DriveRun(sys.argv[1])
    config = Config()
    csv_fname = '/home/mir-alb/Ninad_Thesis/Test/Test.csv'
    csv_header = ['image_fname', 'steering_angle']
    df = pd.read_csv(csv_fname, names=csv_header, index_col=False)
    num_data = len(df)
    text = open('/home/mir-lab/Ninad_Thesis/Test/Salient/Salient.txt', 'w+')
    bar = ProgressBar()
    image_process = ImageProcess()

    for i in bar(range(num_data)):
        image_name = df.loc[i]['image_fname']
        steering = df.loc[i]['steering_angle']
        image_path = '/home/mir-lab/Ninad_Thesis/Test/' + image_name + '.jpg'
        image = utils.load_img(image_path, target_size=(config.image_size[1],
                                                        config.image_size[0]))
        image = image_process.process(image)
        prediction = drive.run(image)
        text.write(str(image_name) + '\t' + str(steering) + '\t' + str(prediction))
        
        modifiers = [None, 'negate', 'small_values']
        for i, modifier in enumerate(modifiers):
            heatmap = visualize_saliency(drive.net_model.model, layer_idx=-1,
                                         filter_indices=0, seed_input=image,
                                         grad_modifier=modifier, keepdims=True)
            final = overlay(image, heatmap, alpha=0.5)
            cv2.imwrite('/home/mir-lab/Ninad_Thesis/Test/Salient/' + image_name + '_' + str(i) + '.jpg', final)
Пример #2
0
    def __init__(self, data_path):
        
        if data_path[-1] == '/':
            data_path = data_path[:-1]

        loc_slash = data_path.rfind('/')
        if loc_slash != -1: # there is '/' in the data path
            model_name = data_path[loc_slash + 1:] # get folder name
            #model_name = model_name.strip('/')
        else:
            model_name = data_path
        csv_path = data_path + '/' + model_name + const.DATA_EXT  # use it for csv file name 
        
        self.csv_path = csv_path
        self.train_generator = None
        self.valid_generator = None
        self.train_hist = None
        self.drive = None
        
        #self.config = Config() #model_name)
        
        self.data_path = data_path
        #self.model_name = model_name
        
        self.drive = DriveData(self.csv_path)
        self.net_model = NetModel(data_path)
        self.image_process = ImageProcess()
        self.data_aug = DataAugmentation()
Пример #3
0
    def recognize(self):
        items = self.tableview_selected_items()
        for tableview_item in items:
            area_range = (self.tool_bar.ui.horizontalSlider.value(),
                          self.tool_bar.ui.horizontalSlider_2.value())
            dilate_size = (self.tool_bar.ui.horizontalSlider_3.value(),
                           self.tool_bar.ui.horizontalSlider_3.value())
            image_process = ImageProcess(tableview_item.data('qpixmap'))
            edge, rects, crops = image_process.recognize_table(
                area_range, dilate_size)

            tableview_item.data('rects_index', 0)
            tableview_item.data('edge', edge)
            tableview_item.data('rects', rects)
            tableview_item.data('crops', crops)

            children = self.model.root().children()
            setting_names = [
                c.data('Settings') for c in children
                if not c.data('Settings') is None
            ]
            setting_names = [
                s for s in setting_names if not s in setting_names
            ]

        if len(items) > 0:
            self.ui.image_view.update_rows(rects)
            self.graphics_view_update()
Пример #4
0
 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
Пример #5
0
    def __init__(self, model_path, data_path):
        if data_path[-1] == '/':
            data_path = data_path[:-1]

        loc_slash = data_path.rfind('/')
        if loc_slash != -1:  # there is '/' in the data path
            model_name = data_path[loc_slash + 1:]  # get folder name
            #model_name = model_name.strip('/')
        else:
            model_name = data_path

        csv_path = data_path + '/' + model_name + const.DATA_EXT

        self.data_path = data_path
        self.data = DriveData(csv_path)

        self.test_generator = None

        self.num_test_samples = 0
        #self.config = Config()

        self.net_model = NetModel(model_path)
        self.net_model.load()
        self.model_path = model_path

        self.image_process = ImageProcess()

        self.measurements = []
        self.predictions = []
        self.differences = []
        self.squared_differences = []
Пример #6
0
def main():
    config = Config()
    image_process = ImageProcess()
    
    try:
        if (len(sys.argv) != 3):
            print('Use model_path image_file_name.')
            return
        
        image = cv2.imread(sys.argv[2])
        image = cv2.resize(image, (config.image_size[0],
                                   config.image_size[1]))
        image = image_process.process(image)

        
        if (len(image) == 0):
            print('File open error: ', sys.argv[2])
            return
        
        drive_run = DriveRun(sys.argv[1])
        measurments = drive_run.run(image) 
        print(measurments)

    except KeyboardInterrupt:
        print ('\nShutdown requested. Exiting...')
Пример #7
0
 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
Пример #8
0
 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
Пример #9
0
def predict_from_camera(drive):
    check, frame = video.read()
    cropImg = frame[yMin:yMax,xMin:xMax]
    newimg = cv2.resize(frame,(160,70))
    image_process = ImageProcess()                              #normalize the image
    IImage = cv2.cvtColor(newimg, cv2.COLOR_RGB2BGR)  
    IImage = image_process.process(IImage)
    prediction= drive.run(IImage)
    print(prediction)
    steering_commands(prediction)
Пример #10
0
    def __init__(self, model_path):

        self.model = None
        self.num_test_samples = 0
        self.config = Config()

        self.net_model = NetModel(model_path)
        self.net_model.load()

        self.image_process = ImageProcess()
Пример #11
0
 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()
Пример #12
0
 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
Пример #13
0
    def __init__(self, model_path):
        model_path = '/home/yadav/lidar_network/balu/lidar_only'
        self.test_generator = None
        self.data_path = None

        self.num_test_samples = 0
        self.config = Config()

        self.net_model = NetModel(model_path)
        self.net_model.load()

        self.image_process = ImageProcess()
Пример #14
0
def main(model_path, input):
    image_file_name = input[0]
    if Config.neural_net['num_inputs'] == 2:
        velocity = input[1]

    image = cv2.imread(image_file_name)
    image_process = ImageProcess()

    # show the image
    fig, (ax1, ax2) = plt.subplots(1, 2)

    ax1.imshow(image)
    ax1.set(title='original image')

    # if collected data is not cropped then crop here
    # otherwise do not crop.
    if Config.data_collection['crop'] is not True:
        image = image[Config.data_collection['image_crop_y1']:Config.
                      data_collection['image_crop_y2'],
                      Config.data_collection['image_crop_x1']:Config.
                      data_collection['image_crop_x2']]

    image = cv2.resize(image, (Config.neural_net['input_image_width'],
                               Config.neural_net['input_image_height']))
    image = image_process.process(image)

    drive_run = DriveRun(model_path)
    if Config.neural_net['num_inputs'] == 2:
        predict = drive_run.run((image, velocity))
        steering_angle = predict[0][0]
        throttle = predict[0][1]
        fig.suptitle('pred-steering:{} pred-throttle:{}'.format(
            steering_angle, throttle))
    else:
        predict = drive_run.run((image, ))
        steering_angle = predict[0][0]
        fig.suptitle('pred_steering:{}'.format(steering_angle))

    ax2.imshow(image)
    ax2.set(title='resize and processed')

    plt.show()
Пример #15
0
    def __init__(self, data_path):

        model_name = data_path[data_path.rfind('/'):]  # get folder name
        model_name = model_name.strip('/')
        csv_path = data_path + '/' + model_name + '.csv'  # use it for csv file name

        self.csv_path = csv_path
        self.train_generator = None
        self.valid_generator = None
        self.train_hist = None
        self.drive = None

        self.config = Config()  #model_name)

        self.data_path = data_path
        #self.model_name = model_name

        self.drive = DriveData(self.csv_path)
        self.net_model = NetModel(data_path)
        self.image_process = ImageProcess()
Пример #16
0
    def recognize(self):
        mainwindow = self.mainwindow(self)
        if mainwindow is None:
            return

        tableview_item = mainwindow.tableview_selected_item()
        if tableview_item is None:
            return
        
        area_range = ( self.ui.horizontalSlider.value(), self.ui.horizontalSlider_2.value() )
        dilate_size = ( self.ui.horizontalSlider_3.value(), self.ui.horizontalSlider_3.value() )
        image_process = ImageProcess( tableview_item.data('qpixmap') )
        edge, rects, crops = image_process.recognize_table(area_range, dilate_size)
        
        tableview_item.data('rects_index', 0)
        tableview_item.data('edge', edge)
        tableview_item.data('rects', rects)
        tableview_item.data('crops', crops)

        self.update_rows()
        self.graphics_view_update()
Пример #17
0
    def __init__(self, model_path, data_path, target_path):
        # remove the last '/' in data and target path if exists
        if data_path[-1] == '/':
            data_path = data_path[:-1]
        if target_path[-1] == '/':
            target_path = target_path[:-1]

        loc_slash = data_path.rfind('/')
        if loc_slash != -1:  # there is '/' in the data path
            data_name = data_path[loc_slash + 1:]  # get folder name
            #model_name = model_name.strip('/')
        else:
            data_name = data_path

        csv_path = data_path + '/' + data_name + const.DATA_EXT

        self.data_name = data_name
        self.data_path = data_path
        self.target_path = target_path + '/' + data_name + '/'
        if os.path.isdir(target_path) is False:
            os.mkdir(target_path)
        if os.path.isdir(self.target_path) is False:
            os.mkdir(self.target_path)

        self.drive_data = DriveData(csv_path)
        self.drive_data.read(normalize=False)
        self.data_len = len(self.drive_data.image_names)

        self.net_model = None
        self.model_path = None
        if model_path is not None:
            from net_model import NetModel

            self.net_model = NetModel(model_path)
            self.net_model.load()
            self.model_path = model_path

        self.image_process = ImageProcess()

        self.display = DisplaySettings()
Пример #18
0
def taker(data):
    joy_pub = rospy.Publisher('/joy', Joy, queue_size=10)
    joy_data = Joy()
    img = ic.imgmsg_to_opencv(data)
    config = Config()
    image_process = ImageProcess()
    IImage = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    IImage = cv2.resize(IImage, (config.image_size[0], config.image_size[1]))
    IImage = image_process.process(IImage)
    #cv2.imwrite('balu.jpg', IImage)
    #drive_run = DriveRun(sys.agrv[1])
    drive_run = DriveRun(
        '/home/mir-lab/Desktop/Balu_Autodrive/2018-06-14-15-16-03')
    prediction = drive_run.run(IImage)
    #print(prediction)
    #print(np.shape(prediction))
    #print(type(prediction))
    if (prediction[0][0] > 0.3):
        #print("1")
        prediction[0][0] = 1
    elif (prediction[0][0] < -0.3):
        #print("2")
        prediction[0][0] = -1
    else:
        #print("3")
        prediction[0][0] = 0
    #new_pred = prediction.astype(np.float)
    #new_predd = np.asscalar(np.array([prediction]))
    #print(type(new_predd))
    #print(np.shape(new_predd))
    #new_predd = joy_data.axes.append(0)
    #0.25 = joy_data.axes.append(3)
    #print(new_predd)
    #print(prediction[0][0])
    joy_data.axes = [prediction[0][0], 0, 0, 0.05, 0, 0]
    joy_pub.publish(joy_data)
Пример #19
0
from PIL import Image
import sys
from image_process import ImageProcess

if __name__ == '__main__':
    Param = sys.argv
    if (len(Param) != 2):
        print ("Usage: $ python3 " + Param[0] + " sample.jpg")
        quit()

    FileName = Param[1]
    try:
        InputImage = Image.open(FileName)
    except:
        print ('faild to load %s' % FileName)
        quit()

    if InputImage is None:
        print ('faild to load %s' % FileName)
        quit()

    ImageProcess = ImageProcess()
    OutputImage = ImageProcess.gray_scale(InputImage)
    OutputImage.save("filtered_" + FileName)
    OutputImage.show()
Пример #20
0
Created on Wed May 15 13:11:00 2019

@author: ninad
"""

import os
import cv2
import pandas as pd
import sys
import numpy as np
from progressbar import ProgressBar

from data_augmentation import DataAugmentation
from image_process import ImageProcess

image_process = ImageProcess()
data_aug = DataAugmentation()

csv_fname = '/home/mir-lab/Ninad_Thesis/Test/Test.csv'
csv_header = ['image_fname', 'steering_angle']
df = pd.read_csv(csv_fname, names=csv_header, index_col=False)
num_data = len(df)
text = open('/home/mir-lab/Ninad_Thesis/Test/Shift/Shift.txt', 'w+')
bar = ProgressBar()
for i in bar(range(num_data)):
    image_name = df.loc[i]['image_fname']
    steering = df.loc[i]['steering_angle']
    image_path = '/home/mir-lab/Ninad_Thesis/Test/' + image_name + '.jpg'
    image = cv2.imread(image_path)
    image = cv2.resize(image, (160, 70))
    image = image_process.process(image)
Пример #21
0
def main(model_path, image_file_path):
    image_process = ImageProcess()

    image = cv2.imread(image_file_path)

    # if collected data is not cropped then crop here
    # otherwise do not crop.
    if Config.data_collection['crop'] is not True:
        image = image[Config.data_collection['image_crop_y1']:Config.
                      data_collection['image_crop_y2'],
                      Config.data_collection['image_crop_x1']:Config.
                      data_collection['image_crop_x2']]

    image = cv2.resize(image, (Config.neural_net['input_image_width'],
                               Config.neural_net['input_image_height']))
    image = image_process.process(image)

    drive_run = DriveRun(model_path)
    measurement = drive_run.run((image, ))
    """ grad modifier doesn't work somehow
    fig, axs = plt.subplots(1, 3)
    fig.suptitle('Saliency Visualization' + str(measurement))
    titles = ['left steering', 'right steering', 'maintain steering']
    modifiers = [None, 'negate', 'small_values']

    for i, modifier in enumerate(modifiers):
        layer_idx = utils.find_layer_idx(drive_run.net_model.model, 'conv2d_last')
        heatmap = visualize_cam(drive_run.net_model.model, layer_idx, 
                    filter_indices=None, seed_input=image, backprop_modifier='guided', 
                    grad_modifier=modifier)

        axs[i].set(title = titles[i])
        axs[i].imshow(image)
        axs[i].imshow(heatmap, cmap='jet', alpha=0.3)
    """
    plt.figure()
    #plt.title('Saliency Visualization' + str(measurement))
    plt.title('Steering Angle Prediction: ' + str(measurement[0][0]))
    layer_idx = utils.find_layer_idx(drive_run.net_model.model, 'conv2d_last')
    heatmap = visualize_cam(drive_run.net_model.model,
                            layer_idx,
                            filter_indices=None,
                            seed_input=image,
                            backprop_modifier='guided')

    plt.imshow(image)
    plt.imshow(heatmap, cmap='jet', alpha=0.5)

    # file name
    loc_slash = image_file_path.rfind('/')
    if loc_slash != -1:  # there is '/' in the data path
        image_file_name = image_file_path[loc_slash + 1:]

    saliency_file_path = model_path + '_' + image_file_name + '_saliency.png'
    saliency_file_path_pdf = model_path + '_' + image_file_name + '_saliency.pdf'

    plt.tight_layout()
    # save fig
    plt.savefig(saliency_file_path, dpi=150)
    plt.savefig(saliency_file_path_pdf, dpi=150)

    print('Saved ' + saliency_file_path + ' & .pdf')
Пример #22
0
    '3': '对比度增强',
    '4': '黑白图像上色',
    '5': '拉伸图像恢复',
    '6': '图像风格转换'
}


def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


app = Flask(__name__)
# 设置静态文件缓存过期时间
app.send_file_max_age_default = timedelta(seconds=1)

ip_obj = ImageProcess(client_id, client_secret)


@app.route('/', methods=['POST', 'GET'])  # 添加路由
def upload():
    filename = '3efe5cc3e397933216ed48f99ad43e02.png'
    if request.method == 'POST':
        file = request.files['file']
        if not (file and allowed_file(file.filename)):
            return jsonify({
                "error": 1001,
                "msg": "请检查上传的图片类型,仅限于png、PNG、jpg、JPG、bmp"
            })
        base_path = os.path.dirname(__file__)  # 当前文件所在路径
        upload_path = os.path.join(base_path, 'static/images')
        if file and allowed_file(file.filename):
Пример #23
0
    def __init__(self, master, screnn_size):
        self.svae_folder_name = None
        FONT_SIZE = 13
        #image
        INPUT_POSITION_X = 10
        INPUT_POSITION_Y = 10
        INPUT_IMAGE_PLACE_Y = 30
        IMAGE_WIDTH = int(screnn_size[0] / 3)
        OUTPUT_PLACE_X = 2 * IMAGE_WIDTH + INPUT_POSITION_X
        DEPTH_PLACE_X = IMAGE_WIDTH + INPUT_POSITION_X
        #button
        BUTTON_WIDTH = 10
        BUTTON_HEIGHT = 2
        WIDHT = int(screnn_size[0] / 2)
        BUTTON_X = 3 * int(WIDHT / 3)
        BUTTON_Y = 800
        RUN_BUTTON_Y = INPUT_POSITION_Y + 40
        VISUAL_BUTTON_Y = RUN_BUTTON_Y + 40
        ON_BUTTON_Y = VISUAL_BUTTON_Y + 40

        self.imgProc = ImageProcess()
        dobi = ImageTk.PhotoImage(Image.open('dobi.png'))

        # input image view
        font = tf.Font(size=FONT_SIZE, weight='bold')
        input_text = tk.Label(text='Input Image', font=font)
        input_text.place(x=INPUT_POSITION_X, y=INPUT_POSITION_Y)
        self.input_image = tk.Label()
        self.upload_image_to_tkinter(self.input_image, dobi, INPUT_POSITION_X,
                                     INPUT_IMAGE_PLACE_Y)

        # output image view
        ouput_text = tk.Label(text='Output Image', font=font)
        ouput_text.place(x=OUTPUT_PLACE_X, y=INPUT_POSITION_Y)
        self.ouput_image = tk.Label()
        self.upload_image_to_tkinter(self.ouput_image, dobi, OUTPUT_PLACE_X,
                                     INPUT_IMAGE_PLACE_Y)

        # Depth Image view
        depth_text = tk.Label(text='Depth Image', font=font)
        depth_text.place(x=DEPTH_PLACE_X, y=INPUT_POSITION_Y)
        self.depth_image = tk.Label()
        self.upload_image_to_tkinter(self.depth_image, dobi, DEPTH_PLACE_X,
                                     INPUT_IMAGE_PLACE_Y)

        # shooting button
        shooting_button = tk.Button(master,
                                    overrelief='solid',
                                    text='CAPTURE',
                                    command=self.shotting,
                                    width=BUTTON_WIDTH,
                                    height=BUTTON_HEIGHT)
        shooting_button.place(x=BUTTON_X, y=BUTTON_Y)

        run_button = tk.Button(master,
                               overrelief='solid',
                               text='RUN',
                               command=self.run,
                               width=BUTTON_WIDTH,
                               height=BUTTON_HEIGHT)
        run_button.place(x=BUTTON_X + 10 * BUTTON_WIDTH + 5, y=BUTTON_Y)

        visual_button = tk.Button(master,
                                  overrelief='solid',
                                  text='VISUAL',
                                  command=self.visual,
                                  width=BUTTON_WIDTH,
                                  height=BUTTON_HEIGHT)
        visual_button.place(x=BUTTON_X + 2 * 10 * BUTTON_WIDTH + 5, y=BUTTON_Y)

        save_button = tk.Button(master,
                                overrelief='solid',
                                text='SAVE',
                                command=self.save,
                                width=BUTTON_WIDTH,
                                height=BUTTON_HEIGHT)
        save_button.place(x=BUTTON_X + 3 * 10 * BUTTON_WIDTH + 5, y=BUTTON_Y)

        self.t1 = threading.Thread(target=self.imgProc.on)
        self.t1.start()