Some videos have frames that have black strips like borders. I have to remove them from the frames. I came up with a crude solution:
import sys, cv2, numpy
i
This problem was already solved in this answer.
In [1]: from PIL import Image, ImageChops
In [3]: im = Image.open('iI3ZE.jpg')
In [4]: def trim(im):
...: bg = Image.new(im.mode, im.size, im.getpixel((0,0)))
...: diff = ImageChops.difference(im, bg)
...: diff = ImageChops.add(diff, diff, 2.0, -100)
...: bbox = diff.getbbox()
...: if bbox:
...: return im.crop(bbox)
...:
In [5]: trim(im).show()
I used Pillow instead of PIL:
pip install pillow
Results in:
