Skip to content

Instantly share code, notes, and snippets.

@aliaminibagh
Last active March 6, 2024 08:53
Show Gist options
  • Save aliaminibagh/0d23dfa44d2c009a5f9f2e95ed2bcb55 to your computer and use it in GitHub Desktop.
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
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