简体   繁体   English

在 Python 中使用 OpenCV2 去除接缝后,如何判断图像的大小?

[英]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.我正在尝试编写一些代码来使用 OpenCV2 从来自 Python 网络摄像头的实时视频中操作单个图像“帧”。 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.您可以使用 Python 子处理调用 ImageMagick 命令行 -trim 函数来删除接触图像两侧的任何黑色。

See https://imagemagick.org/discourse-server/viewtopic.php?f=4&t=35579https://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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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