Skip to content
Snippets Groups Projects
Commit c707806e authored by Kristýna Janků's avatar Kristýna Janků
Browse files

Fixed rectangle creation and added support for testing on N2DH dataset

parent dc5fc49d
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,11 @@ class DatasetFactory(object):
dataset = TrackingNetDataset(**kwargs)
elif 'GOT-10k' == name:
dataset = GOT10kDataset(**kwargs)
# Kristyna Janku: Added option for N2DH dataset, no special attributes are needed, so I just reused
# the GOT10kDataset class
elif 'N2DH' == name:
dataset = GOT10kDataset(**kwargs)
else:
raise Exception("unknow dataset {}".format(kwargs['name']))
raise Exception("unknown dataset {}".format(kwargs['name']))
return dataset
......@@ -4,6 +4,7 @@ import os
import glob
import json
import cv2
import numpy as np
data_path = 'data'
video_list = ['01', '02']
......@@ -42,11 +43,14 @@ for video in video_list:
mask = cv2.convertScaleAbs(mask)
# Checking if tracked object really is in segmented image
if mask.max() == 0:
print('Video: ' + str(num_videos) + ' Frame: ' + frame + ' Missing object id in seg: ' + str(obj_id))
print(f'Video: {video} Frame: {frame} Missing object id in seg: {str(obj_id)}')
else:
# Get bounding box of object from contour
cnt = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]
x, y, w, h = cv2.boundingRect(cnt[0])
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]
areas = [cv2.contourArea(c) for c in contours]
max_index = np.argmax(areas)
max_contour = contours[max_index]
x, y, w, h = cv2.boundingRect(max_contour)
snippets[video][str(obj_id).zfill(2)][frame.zfill(6)] = [x, y, x+w, y+h]
print('Video number: {:d} Snippets count: {:d}'.format(num_videos, len(snippets[video])))
......
......@@ -99,7 +99,7 @@ def crop_video(video, crop_path, instance_size, low, high):
for object_id, files in annotations[video].items():
for filename, bbox in files.items():
filepath = join(data_path, video, 't' + filename[3:] + '.tif')
filepath = join(data_path, video, f't{filename[3:]}.tif')
# Load 16-bit TIFF image, convert it to 8-bit and perform percentile stretch
image_16bit = cv2.imread(filepath, cv2.IMREAD_ANYDEPTH)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment