Esempio n. 1
0
def grid_result_eval(predict_path, log_path='grid_eval.log'):
    pids4probes = np.genfromtxt(predict_path, delimiter=' ')
    probe_shoot = [0, 0, 0, 0, 0]
    for i, pids in enumerate(pids4probes):
        for j, pid in enumerate(pids):
            if pid - i == 775:
                if j == 0:
                    for k in range(5):
                        probe_shoot[k] += 1
                elif j < 5:
                    for k in range(1, 5):
                        probe_shoot[k] += 1
                elif j < 10:
                    for k in range(2, 5):
                        probe_shoot[k] += 1
                elif j < 20:
                    for k in range(3, 5):
                        probe_shoot[k] += 1
                elif j < 50:
                    for k in range(4, 5):
                        probe_shoot[k] += 1
                break
    probe_acc = [shoot / len(pids4probes) for shoot in probe_shoot]
    write(log_path, predict_path + '\n')
    write(log_path,
          '%.2f\t%.2f\t%.2f\n' % (probe_acc[0], probe_acc[1], probe_acc[2]))
    print(predict_path)
    print(probe_acc)
Esempio n. 2
0
def result_eval(predict_path, log_path, TEST, QUERY):
    res = np.genfromtxt(predict_path, delimiter=' ')
    print('predict info get, extract gallery info start')
    test_info = extract_info(TEST)
    print('extract probe info start')
    query_info = extract_info(QUERY)
    print('start evaluate map and rank acc')
    rank1, mAP = map_rank_quick_eval(query_info, test_info, res)
    write(log_path, predict_path + '\n')
    write(log_path, '%f\t%f\n' % (rank1, mAP))
Esempio n. 3
0
def label_cattle_boxes():
    img_pathes = read_lines('data/cattle.txt')
    global cur_box_list
    for img_name in img_pathes:
        cur_box_list = []
        global img, cur_img_path
        cur_img_path = 'data/hard_cattle/' + img_name.strip()
        img = cv2.imread(cur_img_path)
        img = imutils.resize(img, width=400)
        cv2.namedWindow('image')
        cv2.setMouseCallback('image', on_mouse)
        cv2.imshow('image', img)
        cv2.waitKey(0)
        for i in range(len(cur_box_list)):
            cur_line = '%s\t%4f\t%4f\t%4f\t%4f\n' % (
                cur_img_path, float(cur_box_list[i][0][0]) / img.shape[1],
                float(cur_box_list[i][0][1]) / img.shape[0],
                float(cur_box_list[i][1][0]) / img.shape[1],
                float(cur_box_list[i][1][1]) / img.shape[0])
            write('body_box.txt', cur_line)
Esempio n. 4
0
def label_boxes(input_path, output_box_path):
    img_pathes = read_lines(input_path)
    global cur_box_list
    for img_name in img_pathes:
        cur_box_list = []
        global img, cur_img_path
        cur_img_path = img_name.strip()
        img = cv2.imread(cur_img_path)
        img = imutils.resize(img, width=400)
        cv2.namedWindow('image')
        cv2.setMouseCallback('image', on_mouse)
        cv2.imshow('image', img)
        cv2.waitKey(0)
        for i in range(len(cur_box_list)):
            cur_line = '%s\t%4f\t%4f\t%4f\t%4f\n' % (
                cur_img_path, float(cur_box_list[i][0][0]) / img.shape[1],
                float(cur_box_list[i][0][1]) / img.shape[0],
                float(cur_box_list[i][1][0]) / img.shape[1],
                float(cur_box_list[i][1][1]) / img.shape[0])
            write(output_box_path, cur_line)
Esempio n. 5
0
            add_str_on_img(image, total_cnt)
            image_np = load_image_into_numpy_array(image)
            if num > 0:
                # Visualization of the results of a detection.
                result = vis_util.visualize_boxes_and_labels_on_image_array(
                    image_np,
                    np.squeeze(valid_boxes).reshape(num, 4),
                    np.squeeze(valid_classes).astype(np.int32).reshape(num, ),
                    np.squeeze(valid_scores).reshape(num, ),
                    category_index,
                    use_normalized_coordinates=True,
                    min_score_thresh=score_thresh,
                    line_thickness=8)

                Image.fromarray(result).save('detect4video/' +
                                             image_path.split('/')[-1])
                # total_cnt += num

            else:
                if num < 3:
                    write('no_target.txt', image_path + '\n')
                image.save('detect4video/' + image_path.split('/')[-1])
            # plt.figure(figsize=IMAGE_SIZE)
            if num == 0:
                print image_path
        print total_cnt
    os.system('mkdir detect4video2')
    os.system('rm detect4video2/*')
    for i, image_name in enumerate(sorted(os.listdir('detect4video'))):
        shutil.copy('detect4video/' + image_name, 'detect4video2/%05d.jpg' % i)