diff --git a/.image-extraction/ROI_0.png b/.image-extraction/ROI_0.png new file mode 100644 index 0000000..3758878 Binary files /dev/null and b/.image-extraction/ROI_0.png differ diff --git a/.image-extraction/img.jpeg b/.image-extraction/img.jpeg new file mode 100644 index 0000000..fa63228 Binary files /dev/null and b/.image-extraction/img.jpeg differ diff --git a/.image-extraction/main.py b/.image-extraction/main.py new file mode 100644 index 0000000..af7997b --- /dev/null +++ b/.image-extraction/main.py @@ -0,0 +1,27 @@ +import cv2 +import numpy as np + +image = cv2.imread('./img.jpeg') +original = image.copy() +gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) +blurred = cv2.GaussianBlur(gray, (3, 3), 0) +canny = cv2.Canny(blurred, 120, 255, 1) +kernel = np.ones((5,5),np.uint8) +dilate = cv2.dilate(canny, kernel, iterations=1) + +# Find contours +cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) +cnts = cnts[0] if len(cnts) == 2 else cnts[1] + +# Iterate thorugh contours and filter for ROI +image_number = 0 +for c in cnts: + x,y,w,h = cv2.boundingRect(c) + cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 2) + ROI = original[y:y+h, x:x+w] + cv2.imwrite("ROI_{}.png".format(image_number), ROI) + image_number += 1 + +cv2.imshow('canny', canny) +cv2.imshow('image', image) +cv2.waitKey(0)