Commit 2ee7f4df authored by chamodya99's avatar chamodya99

Add Component 2 to the GitLab

parent c398f80d
import torch
import json
import cv2
import math
import os
import random
model_vehicle = torch.hub.load('ultralytics/yolov5', 'yolov5s')
guide_line_database = [527, 215, 611, 345] # sample guideline
def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b):
if x1 >= x2 and y1 >= y2 and x1b <= x2b and y1b <= y2b:
return True
else:
return False
def is_vehicle_parked_correctly(slot_index=0):
sample_imgs = os.listdir('component_2/sample_data')
img = cv2.imread('component_2/sample_data/' + str(random.choice(sample_imgs)))
result = model_vehicle(img)
json_string = result.pandas().xyxy[0].to_json(orient='records')
json_obj = json.loads(json_string)
object_list = []
for i in json_obj:
x = int(i["xmin"])
y = int(i["ymin"])
w = int(i["xmax"])
h = int(i["ymax"])
object_list.append([x, y, w, h])
if len(json_obj) == 0:
return True
return is_inside(object_list[slot_index][0], object_list[slot_index][1], object_list[slot_index][2],
object_list[slot_index][3], guide_line_database[0], guide_line_database[1], guide_line_database[2],
guide_line_database[3])
# print(is_vehicle_parked_correctly())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment