'how to write tagged letters from left to right yolo?
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.X value should be read from smallest to largest, that is, from right to left. 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.
```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 work with yolov4-tiny
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():
#print(class_name)
class_name = class_name.strip() # satır arası boşluklar için
classes.append(class_name)
Initialize camera
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read() # Get frames
(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()```
Can you help me for sorted??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
