I am trying to write some code to manipulate the individual images, "frames", from a live video from the webcam in Python using OpenCV2. I am able to manipulate the frames but I have this excess bit of the image along the edges.
Frame:
I would like the "black areas" to not be in frame so I am wondering how to manipulate the size of the canvas to allow the black areas to not be visible.
What I would like the frame to look like:
Does anyone know what code I could use to crop the canvas size?
You could use a Python subprocessing call to ImageMagick command line -trim function to remove any black that touches the sides of the image.
See https://imagemagick.org/discourse-server/viewtopic.php?f=4&t=35579
Input:
import subprocess
cmd = 'convert seams1.png -fuzz 0% -background black -define trim:percent-background=0% -trim +repage result.png'
subprocess.check_output(cmd, shell=True, universal_newlines=True)
or
import subprocess
cmd = 'convert seams1.png -fuzz 0% -background black -define trim:percent-background=0% -trim +repage result.png'
subprocess.call(cmd, shell=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.