Last active
January 23, 2022 12:49
-
-
Save doleron/f9124848b0863338c38753d37a4fa02b to your computer and use it in GitHub Desktop.
Python unwrapping the data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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