Last active
March 6, 2024 08:53
-
-
Save aliaminibagh/0d23dfa44d2c009a5f9f2e95ed2bcb55 to your computer and use it in GitHub Desktop.
A function for draw rectangle using yolo text file on input image and save the result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
def draw_rectangles_from_yolo(image_path, text_file_path, output_image_name): | |
image = cv2.imread(image_path) | |
with open(text_file_path, 'r') as file: | |
lines = file.readlines() | |
for line in lines: | |
data = line.split() | |
x, y, w, h = map(int, data[1:]) | |
cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 0), 2) | |
cv2.imwrite(output_image_name, image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment