-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Position about Label Texts in Detecting #11525
Comments
Sorry for the terrible code type. I don't know how to change it😭 |
@AlecMaxPro no worries, we understand that coding can be difficult at times! From your code snippet, it seems like you are trying to draw boxes and label texts for three different classes. However, you are seeing 'without_helmet' label texts even though you do not have any related code for it. One thing that stands out is that the code for drawing the box and label text is running for every label, regardless of the class. This means that if you have labels for a certain class, but no specific code for that class in your snippet, it will still draw a box and label text using the previously assigned color and font thickness. To solve this issue, you can add an 'else' statement after all the 'if' conditions for each class, which will ensure that no code is run if the label does not belong to any of the three classes specified. Additionally, you can try adding print statements to check the actual contents of the label variable to see if it contains unwanted text. I hope this helps! Let us know if you have any further questions. |
Thanks a lot. According to your tips, I have dealt with my problem. |
@AlecMaxPro you're welcome! We're glad to hear that our tips helped solve your problem. If you have further questions or issues, feel free to open a new issue and we'll be happy to assist you. Thank you for using YOLOv5! |
Search before asking
Question
Hi, I'm a little confused about this question.
I have three classes: moped, helmet and without_helmet. I'm trying to put different positions according to class txts due to the occlusion between the label txts.
So this is my code about def box_labels in utils.py But when I detect the pictures, I found the 'without_helmet' label text even I don't any code about 'without_helmet', like this pictures
else: # cv2 p1, p2 = (int(box[0]), int(box[1])), (int(box[2]), int(box[3])) tf = max(self.lw - 1, 1) # font thickness tf = 2 if 'moped' in label: color = (255, 0, 0) # BGR cv2.rectangle(self.im, p1, p2, color, thickness=tf, lineType=cv2.LINE_AA) if 'helmet' in label: color = (0, 255, 0) cv2.rectangle(self.im, p1, p2, color, thickness=tf, lineType=cv2.LINE_AA) if 'without_helmet' in label: color = (0, 0, 255) cv2.rectangle(self.im, p1, p2, color, thickness=tf, lineType=cv2.LINE_AA) if label: tf = max(self.lw - 1, 1) # font thickness w, h = cv2.getTextSize(label, 0, fontScale=self.lw / 4, thickness=tf)[0] # text width, height # outside = p1[1] - h - 3 >= 0 # label fits outside box # p2 = p1[0] + w, p1[1] - h - 3 if outside else p1[1] + h + 3 if 'moped' in label: p3 = p1[0] + w, p1[1] - h - 3 cv2.rectangle(self.im, p1, p3, color, -1, cv2.LINE_AA) # filled cv2.putText(self.im, label, p1, 0, self.lw / 4, txt_color, thickness=tf, lineType=cv2.LINE_AA) if 'helmet' in label: p3 = p2[0] - w, p2[1] + h cv2.rectangle(self.im, p2, p3, color, -1, cv2.LINE_AA) # filled cv2.putText(self.im, label, p3, 0, self.lw / 4, txt_color, thickness=tf, lineType=cv2.LINE_AA)
But if I add some codes about 'without_helmet' text like, there will be two 'without_helmet' label texts in the detected picture.
if 'without_helmet' in label: p3 = p2[0] + w, p2[1] + h cv2.rectangle(self.im, p2, p3, color, -1, cv2.LINE_AA) # filled cv2.putText(self.im, label, p3, 0, self.lw / 4, txt_color, thickness=tf, lineType=cv2.LINE_AA)
Thank you for answering!
Additional
These are two pictures I mentioned.
The text was updated successfully, but these errors were encountered: