简体   繁体   中英

How to tell what the size of an image is after removing seams in using OpenCV2 in Python?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM