15,743,541 members
See more: , +
So basically I have an image with whitespace and a text above.
The output should be only the picture. Without the text and the whitespaces. The best example would probably be a meme:

https://i.stack.imgur.com/03Tmo.jpg

How could I implement this?

What I have tried:

I believe I would have to get the corner coordinates and then use something like pillow's
Python
`Image.crop(corner_coordinates)`

I tried the Canny Edge Detection Algorithm (opencv). Im now getting the desired edges bit also the edges from the text. Would be nice if someone could help me:)
Posted
Updated 1-Oct-20 6:55am

## Solution 1

import cv2
import numpy as np
blurred = cv2.blur(img, (3,3))
canny = cv2.Canny(blurred, 50, 200)

## find the non-zero min-max coords of canny
pts = np.argwhere(canny>0)
y1,x1 = pts.min(axis=0)
y2,x2 = pts.max(axis=0)

## crop the region
cropped = img[y1:y2, x1:x2]
cv2.imwrite("cropped.png", cropped)

tagged = cv2.rectangle(img.copy(), (x1,y1), (x2,y2), (0,255,0), 3, cv2.LINE_AA)
cv2.imshow("tagged", tagged)
cv2.waitKey()