Exemplo n.º 1
0
 def test_detect_interesting_points(self):
     image_file = data_dir + "/test/karyotype.bmp"
     image = image_utils.read_image(image_file)
     chromosomes = Pipeline.extract_chromosomes(image)
     straightened_chromosomes = Pipeline.straighten_chromosomes(chromosomes)
     _ = Pipeline.detect_interesting_points(straightened_chromosomes,
                                            verbose=True)
Exemplo n.º 2
0
def single_box_in_single_frame_tracking(frame_files, frame_id, box_id,
                                        annotations, tracking_threshold,
                                        forward_tracker, backward_tracker,
                                        offset, low, high):
    num_frame = len(frame_files)

    box = [int(x) for x in annotations[frame_id][box_id]["bbox"]]
    category_id = annotations[frame_id][box_id]["category_id"]

    boxes = list()

    # Forward tracking
    is_first_frame = True
    for tracking_frame_id in range(
            frame_id,
            min(num_frame + offset,
                frame_id + high)):  # cut off by range specified by "high"
        # print(f"===> Process frame {tracking_frame_id} w.r.t file {frame_files[tracking_frame_id]}")
        frame = image_utils.read_image(frame_files[tracking_frame_id - offset])

        if is_first_frame:
            forward_tracker.init(frame, box)
            is_first_frame = False
            continue  # TODO: Is this necessary?

        outputs = forward_tracker.track(frame)

        tracking_score = outputs["best_score"]
        # print("===> Tracking score: ", tracking_score)
        if tracking_score < tracking_threshold:
            # print("===> Break")
            break

        bbox = list(map(int, outputs['bbox']))

        # draw_frame = frame.copy()
        # draw_frame = cv2.rectangle(draw_frame, (bbox[0], bbox[1]), (bbox[0] + bbox[2], bbox[1] + bbox[3]),
        #                            (0, 255, 0), 3)
        # image_utils.show_images([draw_frame])

        boxes.append({
            "bbox": bbox,
            "score": float(tracking_score),
            "category_id": category_id,
            "image_id": tracking_frame_id
        })

    # Backward tracking
    is_first_frame = True
    for tracking_frame_id in reversed(
            range(max(offset, frame_id - low),
                  frame_id + 1)):  # cut off by range specified by "low"
        # print(f"==> Process frame {tracking_frame_id} w.r.t file {frame_files[tracking_frame_id]}")
        frame = image_utils.read_image(frame_files[tracking_frame_id - offset])

        if is_first_frame:
            backward_tracker.init(frame, box)
            is_first_frame = False
            continue  # TODO: Is this necessary?

        outputs = backward_tracker.track(frame)

        tracking_score = outputs["best_score"]
        # print("===> Tracking score: ", tracking_score)
        if tracking_score < tracking_threshold:
            # print("===> Break")
            break

        bbox = list(map(int, outputs['bbox']))

        # draw_frame = frame.copy()
        # draw_frame = cv2.rectangle(draw_frame, (bbox[0], bbox[1]), (bbox[0] + bbox[2], bbox[1] + bbox[3]),
        #                            (0, 255, 0), 3)
        # image_utils.show_images([draw_frame])

        boxes.append({
            "bbox": bbox,
            "score": float(tracking_score),
            "category_id": category_id,
            "image_id": tracking_frame_id
        })

    return boxes
Exemplo n.º 3
0
 def test_straighten_chromosomes(self):
     image_file = data_dir + "/test/karyotype.bmp"
     image = image_utils.read_image(image_file)
     chromosomes = Pipeline.extract_chromosomes(image)
     _ = Pipeline.straighten_chromosomes(chromosomes, debug=True)
Exemplo n.º 4
0
 def test_extract_chromosomes(self):
     image_file = data_dir + "/test/karyotype.bmp"
     image = image_utils.read_image(image_file)
     chromosomes = Pipeline.extract_chromosomes(image)
     for chromosome in chromosomes:
         image_utils.show_image(chromosome, cmap=None)
Exemplo n.º 5
0
 def test_generate_chromosome_cluster(self):
     image_file = data_dir + "/test/karyotype.bmp"
     image = image_utils.read_image(image_file)
     image_utils.show_image(image)
     chromosome_cluster = Pipeline.generate_chromosome_cluster(image)
     image_utils.show_image(chromosome_cluster, cmap=None)
Exemplo n.º 6
0
from tqdm import tqdm

import argparse

parser = argparse.ArgumentParser(description='tracking demo')
parser.add_argument('--raw_dir', type=str, help='path to frame files')
parser.add_argument('--tracking_dir', type=str, help='path to tracking_json')
parser.add_argument('--result_dir',
                    type=str,
                    help='path to save visualized results')
args = parser.parse_args()

raw_detection = general_utils.get_all_files(args.raw_dir,
                                            keep_dir=True,
                                            sort=True)
tracking_detection = general_utils.get_all_files(args.tracking_dir,
                                                 keep_dir=True,
                                                 sort=True)

general_utils.create_directory(args.result_dir)

num_frame = len(raw_detection)

for i in tqdm(range(num_frame)):
    raw = image_utils.read_image(raw_detection[i])
    tracking = image_utils.read_image(tracking_detection[i])

    combined = np.concatenate([raw, tracking], axis=1)
    cv2.imwrite(f"{args.result_dir}/frame_{'{:06d}'.format(i + 1)}.jpg",
                combined)