Commit d0d57bc4 authored by @Thilakasiri_M.D.T.S's avatar @Thilakasiri_M.D.T.S

Update component 2

parent 2ee7f4df
...@@ -7,7 +7,7 @@ import random ...@@ -7,7 +7,7 @@ import random
model_vehicle = torch.hub.load('ultralytics/yolov5', 'yolov5s') model_vehicle = torch.hub.load('ultralytics/yolov5', 'yolov5s')
guide_line_database = [527, 215, 611, 345] # sample guideline guide_line_database = [180, 270, 520, 750] # sample guideline
def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b): def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b):
...@@ -18,9 +18,12 @@ def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b): ...@@ -18,9 +18,12 @@ def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b):
def is_vehicle_parked_correctly(slot_index=0): def is_vehicle_parked_correctly(slot_index=0):
# sample_imgs = os.listdir('sample_data')
sample_imgs = os.listdir('component_2/sample_data') sample_imgs = os.listdir('component_2/sample_data')
# read_filename = 'sample_data/' + str(random.choice(sample_imgs))
img = cv2.imread('component_2/sample_data/' + str(random.choice(sample_imgs))) read_filename = 'component_2/sample_data/' + str(random.choice(sample_imgs))
img = cv2.imread(read_filename)
# img = cv2.imread('component_2/sample_data/' + str(random.choice(sample_imgs)))
result = model_vehicle(img) result = model_vehicle(img)
json_string = result.pandas().xyxy[0].to_json(orient='records') json_string = result.pandas().xyxy[0].to_json(orient='records')
...@@ -34,14 +37,32 @@ def is_vehicle_parked_correctly(slot_index=0): ...@@ -34,14 +37,32 @@ def is_vehicle_parked_correctly(slot_index=0):
y = int(i["ymin"]) y = int(i["ymin"])
w = int(i["xmax"]) w = int(i["xmax"])
h = int(i["ymax"]) h = int(i["ymax"])
name = i["name"]
# cv2.rectangle(img, (x, y), (w, h), (0, 255, 0), 2)
# print((x, y), (w, h))
# cv2.rectangle(img, (guide_line_database[0], guide_line_database[1]),
# (guide_line_database[2], guide_line_database[3]), (0, 0, 255), 2)
# cv2.imwrite('out/out.png', img)
object_list.append([x, y, w, h]) object_list.append([x, y, w, h])
if len(json_obj) == 0: if len(json_obj) == 0:
return True cv2.putText(img, 'Correct', (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imwrite('out/out.png', img)
return True, read_filename
if 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]):
cv2.putText(img, 'Correct', (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imwrite('out/out.png', img)
else:
cv2.putText(img, 'Incorrect', (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2)
cv2.imwrite('out/out.png', img)
return is_inside(object_list[slot_index][0], object_list[slot_index][1], object_list[slot_index][2], 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], object_list[slot_index][3], guide_line_database[0], guide_line_database[1], guide_line_database[2],
guide_line_database[3]) guide_line_database[3])
# print(is_vehicle_parked_correctly()) # print(is_vehicle_parked_correctly())
import cv2
img = cv2.imread('sample_data/0001.jpg')
img = cv2.resize(img, (630, 420))
cv2.imwrite('1.jpg', img)
print(img.shape)
img2 = cv2.imread('sample_data/0002.jpg')
img2 = cv2.resize(img2, (630, 420))
cv2.imwrite('2.jpg', img2)
print(img2.shape)
img3 = cv2.imread('sample_data/0003.jpg')
img3 = cv2.resize(img3, (630, 420))
cv2.imwrite('3.jpg', img3)
print(img3.shape)
\ No newline at end of file
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