theAIGuysCode / yolov4-deepsort

Object tracking implemented with YOLOv4, DeepSort, and TensorFlow.
GNU General Public License v3.0
1.31k stars 745 forks source link

how to write tagged letters from left to right? #129

Open ozicmoi opened 2 years ago

ozicmoi commented 2 years ago

Search before asking

I have searched the YOLOv5 [issues](https://github.com/ultralytics/yolov5/issues) and [discussions](https://github.com/ultralytics/yolov5/discussions) and found no similar questions.

Question

I trained 2 yolov4-tiny models for my license plate recognition system. The first is the fog plate region label, the second is the char labels (letters and numbers). The Turkish alphabet is read from left to right. That's why I want to sort the tagged letters in the frame according to the x position. When I don't do this, the order is wrong.

I handled it with the code below with yolov5 before. But I couldn't solve my problem because I don't know if there is a function named sorted_values in the yolov4-tiny model.

That is Yolov5(Left to right)

results1 = model(frame) results1.pandas().xyxy[0].sort_values('xmin') plate_num = str(results1.pandas().xyxy[0].sort_values('xmin').name.values) clean_text2 = "" for char in plate_num: if char in "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ": clean_text2 += char plate_num = clean_text2 plate_num = plate_num.replace(" ", "").replace("\n", "")

This is My Code

import cv2

net = cv2.dnn.readNet("dnn_model/char-yolov4-tiny.weights", "dnn_model/char-yolov4-tiny.cfg") model = cv2.dnn_DetectionModel(net) model.setInputParams(size=(320, 320), scale=1/255)

plate_num=""

classes = [] with open("dnn_model/char-classes.txt", "r") as file_object: for class_name in file_object.readlines():

class_name = class_name.strip()

classes.append(class_name)

cap = cv2.VideoCapture(0)

while True:

ret, frame = cap.read() # Get frames Screenshot from 2022-02-22 11-13-42

(class_ids, scores, bboxes) = model.detect(frame, confThreshold=0.3, nmsThreshold=.4) for class_id, score, bbox in zip(class_ids, scores, bboxes): (x, y, w, h) = bbox cv2.rectangle(frame, (x, y), (x + w, y + h), (200,0,50), 3) class_name = classes[class_id]

cv2.putText(frame, class_name, (x, y - 10), cv2.FONT_HERSHEY_PLAIN, 3, (200,0,50), 2)

cv2.imshow("Frame", frame) plate_num+=class_name print(plate_num) key = cv2.waitKey(1)

if cv2.waitKey(1) & 0xFF == ord('q'): break

cap.release() cv2.destroyAllWindows()