Example #1
0
def uploadUGProductImage(request):
	if request.method == 'POST':
		process_image(request.POST["product1_url"], request.POST["product1_filename"])
		process_image(request.POST["product2_url"], request.POST["product2_filename"])
		# use process_images.py
		return HttpResponse("looks like it worked")
	return HttpResponse("Not a post request")
Example #2
0
def main(cards_file, debug=False):
    with open(cards_file) as f:
        content = f.readlines()

    card_list = [line.rstrip('\n') for line in content]

    download_images(card_list)

    for card_name in card_list:
        print(card_name)
        process_image(card_name, debug)
Example #3
0
def predict(image_path, category_names, model, top_k, device):
    device = torch.device(
        "cuda:0" if torch.cuda.is_available() and device == 'gpu' else 'cpu')

    image = process_image(image_path)
    tensor_im = torch.from_numpy(image)
    tensor_im = tensor_im.permute(2, 0, 1).type(torch.cuda.FloatTensor)
    tensor_im = tensor_im.unsqueeze(0)

    with torch.no_grad():
        model.to(device)
        tensor_im.to(device)
        output = model.forward(tensor_im)
        probs = torch.exp(output)

    probabilities, idx = torch.topk(probs, top_k)
    idx = idx.cpu().numpy()[0]
    probabilities = probabilities.cpu().numpy()[0]
    classes = {val: key for key, val in model.class_to_idx.items()}
    top_classes = [classes[each] for each in idx]

    with open(category_names, 'r') as f:
        category_names = json.load(f)
    label_idx = re.split('/', image_path)
    label_idx = label_idx[2]
    label = category_names[label_idx]

    predicted_labels = [category_names[i] for i in top_classes]
    round_prob = list(np.around(np.array(probabilities), 2))
    predict_dict = dict(zip(predicted_labels, round_prob))

    print('Predicted Image Label: ', label)
    print('Top ' + str(top_k) + ' Probabilities')
    for k, v in predict_dict.items():
        print(str(k) + ': ' + str(v))
Example #4
0
def main(img):
    #返回车牌定位
    cropImg = image_position(img)
    #车牌倾斜矫正
    rotated = correct_image(cropImg)
    #分割字符
    images = process_image(rotated)
    #预测
    prediction(images)
Example #5
0
def make_voc(imlist):
    featlist = [ process_image(im) for im in imlist ]

    voc = Vocabulary(VOC_NAME)
    voc.train(featlist, 1000, 10)

    # saving vocabulary
    with open(VOC_FILE, 'wb') as f:
        cPickle.dump(voc, f)
    print 'vocabulary', voc.name, 'has', voc.nbr_words, 'words'
Example #6
0
def unify_test_function(model, batch):
    if len(batch) == 3:
        x, y, _ = batch
    else:
        x, y = batch

    x, y = x.to(model.device), y.to(model.device)
    pred = process_image(model, x, model.input_size, model.n_channels)
    loss = F.mse_loss(pred.detach(), y)
    pcc = pearson_corrcoef(pred.reshape(-1), y.reshape(-1))
    return pred.detach(), loss.detach(), pcc.detach()
def telemetry(sid, data):
    if data:
        # The current steering angle of the car
        steering_angle = data["steering_angle"]
        # The current throttle of the car
        throttle = data["throttle"]
        # The current speed of the car
        speed = data["speed"]
        # The current image from the center camera of the car
        imgString = data["image"]
        image = Image.open(BytesIO(base64.b64decode(imgString)))
        image_array = np.asarray(image)


        image_4d = image_array[None, :, :, :]

        # Pre-process
        image_3d = process_image(convert_4d_to_3d(image_4d))
        image_4d = convert_3d_to_4d(image_3d)

        steering_angle = float(model.predict(image_4d, batch_size=1))

        #throttle = controller.update(float(speed))
        throttle = 0.2

        print(steering_angle, throttle)
        send_control(steering_angle, throttle)

        # save frame
        if args.image_folder != '':
            timestamp = datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S_%f')[:-3]
            image_filename = os.path.join(args.image_folder, timestamp)
            image.save('{}.jpg'.format(image_filename))
    else:
        # NOTE: DON'T EDIT THIS.
        sio.emit('manual', data={}, skip_sid=True)
def test_process_image():
    assert pi.process_image(TEST_IMAGE) != None
Example #9
0
def pipe_images():
    # if not request.json or not 'data' in request.json:
    #     abort(400)
    print(request.json)
    result = cf.process_image(request.json.get("data"))
    return jsonify({"status": result[0], "name": result[1]}), 201