|
|
import cv2
image = cv2.imread("logo.jpg", 1)
img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.threshold(img, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU, img) cv2.bitwise_not(img, img)
rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (30, 5))
img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, rect_kernel) contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
if len(contours) != 0: ROI_number = 0 for c in contours: x,y,w,h = cv2.boundingRect(c)
# Depends on text size, so the greater the value the less objects we get. if (h > 50): cv2.rectangle(image, (x,y), (x+w,y+h), (0,0,255), 1)
ROI = image[y:y+h, x:x+w] cv2.imwrite('results/ROI_{}.png'.format(ROI_number), ROI) ROI_number += 1
cv2.imshow("Result", image) cv2.waitKey(0)
|