def generate_data():
    '''
    Execute data generation for multiple parameters
    '''
    paths_base = map('./input/{}.png'.format, NAMES)
    paths_globbed = map(glob.glob, paths_base)
    paths = list(itertools.chain.from_iterable(paths_globbed))

    for preprocess in PREPORCESS:
        for lang in LANGS:
            for method in METHODS:
                config_name = '{}__{}__{}'.format(preprocess, lang, method)

                for image_path in paths:
                    page_index = get_page_index(image_path)

                    base_name = image_path[-9:-4]

                    has_result = path.isfile('./results/{}/{}.csv'.format(
                        config_name, base_name))

                    if has_result:
                        print(
                            '\nresult file for "{}" already exists, skipping...'
                            .format(base_name))
                    else:
                        process_image(image_path, preprocess, lang, method,
                                      False, config_name)

                        print("==========\nProcessing p.{} done!\n".format(
                            page_index))
Example #2
0
def take_image():
    name = request.form['name']
    # print(name)
    _, frame = video.read()

    cv2.imwrite(f'{name}.jpg', frame)
    processing.process_image(f'{name}.jpg')

    return Response(status=200)
def predict(image_path, model, top_k, category_names):
    '''
    Image object ==> top k classes predicted by model along with their probabilities 
    
    This function has three inputs: picture path, mode, and number of top k classes predicted by the model.
    It takes a picture from given path, applys necessary processing, uses the picture for prediction and returns 
    top k classes predicted by the model.
    '''
    my_model = tf.keras.models.load_model(
        model, custom_objects={'KerasLayer': hub.KerasLayer})

    im = Image.open(image_path)
    test_image = np.asarray(im)
    processed_test_image = process_image(test_image)

    ## Model accepts 4-dimension array. To satisfy this requirement we need to expand the processed image of 3 dims to 4 dims
    processed_test_image = np.expand_dims(processed_test_image, axis=0)
    print('Expanded processed image shape is:', processed_test_image.shape)

    ## Read Json file
    with open(category_names, 'r') as f:
        class_names = json.load(f)

    ## predict
    ps = my_model.predict(processed_test_image)

    ## Extract probaility and class label for top k classes with highest probability
    indeces = ps.argsort()[0][::-1][:top_k].tolist()
    probs = ps[0][indeces].tolist()
    classes = [str(i) for i in indeces]
    flowers_name = [
        class_names[str(x + 1)] for x in indeces
    ]  # add 1 to correspond the indexes from the prediction to the indexes in the class_names
    return probs, classes, flowers_name
def main():
    '''
    Execute full recognition process
    '''
    args = parse_main_arguments()

    names = args['names']
    preprocess_mode = args['preprocess']
    language = args['lang']
    method = args['method']
    debug = args['debug']
    config_name = args['config_name']

    paths_base = map('./input/{}.png'.format, names)
    paths_globbed = map(glob.glob, paths_base)
    paths = list(itertools.chain.from_iterable(paths_globbed))

    for image_path in paths:
        page_index = get_page_index(image_path)

        processing_result = process_image(image_path, preprocess_mode,
                                          language, method, debug, config_name)

        print("==========\nResults p.{}:\n".format(page_index))
        print(processing_result)
Example #5
0
def process_images():
    for i in range(6):
        name = 'test_images/test{}.jpg'.format(i + 1)
        inpimg = mpimg.imread(name)
        print("processing=", name)
        start = time.time()
        result = process_image(inpimg, key=name)
        stop = time.time()
        plt.title("{} {}m".format(name, (stop - start) / 60))
        plt.imshow(result)
        plt.show()
Example #6
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)

        file = request.files['file']

        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            processing.process_image(
                os.path.join(app.config['UPLOAD_FOLDER'], filename))

            return redirect(
                url_for('uploaded_file', filename='processed_image.jpg'))

    return redirect(url_for('index'))
Example #7
0
def process_frames():
    clip1 = VideoFileClip("test_video.mp4")
    #video_ouptut = 'project_detection_video.mp4'
    #clip1 = VideoFileClip("project_video.mp4")

    counter = 0
    for f in clip1.iter_frames():
        if counter == 6:
            break
        mpimg.imsave("frames/frame{}.jpg".format(counter), f)
        processed_clip, heatmap, labels = process_image(
            f, heatmap_and_labels=True)
        mpimg.imsave("frames/processed{}.jpg".format(counter), processed_clip)
        mpimg.imsave("frames/heatmap{}.jpg".format(counter), heatmap)
        mpimg.imsave("frames/labels{}.jpg".format(counter), labels[0])
        # mpimg.imsave( "frames/total_labels{}.jpg".format(counter),total_labels)
        # mpimg.imsave( "frames/clean2-{}.jpg".format(counter),clean2)
        counter += 1
Example #8
0
def video_image_processor_callback(img):
    result = process_image(img)
    return result
Example #9
0
from processing import process_image

for i in xrange(4, 0, -1):
    time.sleep(1)
    print i

last_time = time.time()
while 1:
    screen = np.array(ImageGrab.grab(bbox=(320, 240, 940, 700)))

    cv2.imshow("Screen", screen)

    print('frame took {} seconds'.format(time.time() - last_time))
    last_time = time.time()

    new_screen, original = process_image(screen)

    cv2.imshow("Canny Edges", new_screen)
    cv2.imshow("Original", original)
    cv2.imshow("Screen", screen)

    logging.basicConfig(filename='frame_info.log', level=logging.DEBUG)
    logging.info('Time {} seconds'.format(time.time() - last_time))

    log_file = open('log_file', 'ab+')
    log_file.write('Time {} seconds'.format(time.time() - last_time))

    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break
Example #10
0
from processing import process_image

labels = ["ibrahim", "ayush"]

for label in labels:
    for i in range(20):
        file_name = label + "_left_" + str(i) + ".jpg"
        print(file_name)
        process_image("data/raw/" + file_name, "data/processed/" + file_name)

    for i in range(20):
        file_name = label + "_right_" + str(i) + ".jpg"
        print(file_name)
        process_image("data/raw/" + file_name, "data/processed/" + file_name)
Example #11
0
 def fetch_image(self, image, destfile):
     with tempfile.NamedTemporaryFile(suffix='.png') as downloadfile:
         self.epic.download_image(image['image'], downloadfile)
         process_image(downloadfile.name, destfile.name)
Example #12
0
 def fetch_image(self, image, destfile):
     with tempfile.NamedTemporaryFile(suffix='.png') as downloadfile:
         self.epic.download_image(image, downloadfile)
         process_image(downloadfile.name, destfile.name)
        if (len(self.accel) > 0):
            print(accel, mean, self.accel.mean())

        self.lane_points = new_lane_points
        self.push(new_lane_points)
        return (accel, mean, new_lane_points)
        # Somehow need to threshold hte lane points.


LEFT_LANE_INFO = LaneInfo(650)
RIGHT_LANE_INFO = LaneInfo(500)  # 500 is best

if PROCESS_MOVIE == False:
    # inpimg = mpimg.imread('test_images/test1.jpg')
    inpimg = mpimg.imread('test_images/left-lane-at-barrier.jpg')
    inpimg = mpimg.imread('test_images/error_prone_image.jpg')
    inpimg = mpimg.imread('test_images/test1_tree_infront.jpg')

    result = process_image(inpimg, LEFT_LANE_INFO, RIGHT_LANE_INFO)

    plt.title("End result")
    plt.imshow(result)
    plt.show()

else:
    video_output = 'processed_video.mp4'
    clip1 = VideoFileClip("project_video.mp4")

    processed_clip = clip1.fl_image(p)
    processed_clip.write_videofile(video_output, audio=False)
Example #14
0
# coding=utf-8
from __future__ import division, absolute_import, print_function, unicode_literals
import tempfile
from datetime import date
from epic import EPIC
from processing import process_image

e = EPIC()

i = 0
for image in e.get_image_range(date(2015, 10, 13), date(2015, 10, 21)):
    with tempfile.NamedTemporaryFile(suffix='.png') as downloadfile:
        e.download_image(image['image'], downloadfile)
        process_image(downloadfile.name, "./out/img%03d.png" % i)
    i += 1

# avconv -f image2 -r 30 -i ./img%03d.png -s 1024x1024 ./output.mp4
Example #15
0
def p(img):
    # Image call back for processing video
    result = process_image(img)
    return result
def p(img):
    global LEFT_LANE_INFO, RIGHT_LANE_INFO
    result = process_image(img, LEFT_LANE_INFO, RIGHT_LANE_INFO)
    return result
Example #17
0
from processing import process_image
from servo import actuate, cleanup, init_GPIO, reset

servo = init_GPIO()
img_shape = (224, 224)
model_path = "./data/palm_vein_model.h5"
raw_img_path = "pic.jpg"
processed_img_path = "thr.jpg"

while (True):
    input = raw_input("Ready.\n")
    if "run" == input:
        subprocess.call("./take_pic.sh")
        print("image taken")
        post_original()
        process_image(raw_img_path, processed_img_path, img_shape)
        res = post_processed()

        isAuthenticated = False
        if res == 't':
            isAuthenticated = True

        if (isAuthenticated):
            actuate(servo)

    elif "lock" == input:
        reset(servo)
    elif "quit" == input:
        cleanup(servo)
        break
    else: