如果我有一个带有 alpha 通道的 QImage,如何创建一个新的 QImage,它被裁剪到不透明区域的边界框?
问问题
1564 次
2 回答
1
I found another SO answer (in C++) that does this:
Does Qt have a way to find bounding box of an image?
def bbox(p):
bounding-box-of-an-image
l = p.width()
t = p.height()
r = 0
b = 0
for y in range(p.height()):
rowFilled = False
for x in range(p.width()):
if qAlpha(p.pixel(x, y)):
rowFilled = True
r = max(r, x)
if l > x:
l = x
if rowFilled:
t = min(t, y)
b = y
return QRect(QPoint(l, t), QPoint(r, b))
but it would be great if there were a better/faster way to do this.
于 2012-08-09T16:45:21.033 回答
1
您要实现的是图像处理的一部分。这不是 QImage 中的标准操作。您必须遍历像素并计算边界框。我建议您使用 cv libs 因为它们对此类操作很有用。
于 2012-08-10T05:25:37.137 回答