Skip to content

Instantly share code, notes, and snippets.

@qmaruf
Last active January 21, 2020 03:04
Show Gist options
  • Save qmaruf/52545c06f8b71e3e73f682be5471bab9 to your computer and use it in GitHub Desktop.
Save qmaruf/52545c06f8b71e3e73f682be5471bab9 to your computer and use it in GitHub Desktop.
from PIL import Image, ImageDraw
import cv2
def draw_rect(img, box, img_src):
x1, y1, x2, y2 = map(int, box)
if img_src == 'pil':
draw = ImageDraw.Draw(img)
draw.rectangle(((x1, y1), (x2, y2)), width=10, outline="red")
del draw
elif img_src == 'cv2':
img = cv2.rectangle(img, (x1, y1), (x2, y2), (0, 0, 255), 4)
return img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment