Skip to content

Instantly share code, notes, and snippets.

@doleron
Last active January 23, 2022 12:49
Show Gist options
  • Save doleron/f9124848b0863338c38753d37a4fa02b to your computer and use it in GitHub Desktop.
Save doleron/f9124848b0863338c38753d37a4fa02b to your computer and use it in GitHub Desktop.
Python unwrapping the data
def unwrap_detection(input_image, output_data):
class_ids = []
confidences = []
boxes = []
rows = output_data.shape[0]
image_width, image_height, _ = input_image.shape
x_factor = image_width / 640
y_factor = image_height / 640
for r in range(rows):
row = output_data[r]
confidence = row[4]
if confidence >= 0.4:
classes_scores = row[5:]
_, _, _, max_indx = cv2.minMaxLoc(classes_scores)
class_id = max_indx[1]
if (classes_scores[class_id] > .25):
confidences.append(confidence)
class_ids.append(class_id)
x, y, w, h = row[0].item(), row[1].item(), row[2].item(), row[3].item()
left = int((x - 0.5 * w) * x_factor)
top = int((y - 0.5 * h) * y_factor)
width = int(w * x_factor)
height = int(h * y_factor)
box = np.array([left, top, width, height])
boxes.append(box)
return class_ids, confidences, boxes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment