gpt4 book ai didi

selection - Gimp python-fu 如何选择多边形?

转载 作者:行者123 更新时间:2023-12-04 02:09:52 25 4
gpt4 key购买 nike

问题

我需要在图像上进行数百次多边形选择。为了提供帮助,我一直在尝试使用 python 控制台创建一个脚本,该脚本将以计算的方式执行此操作(相同大小的区域,数百个不同的起点)。我在 Windows 10 机器上使用 GIMP 2.8.18。

问题是函数 pdb.gimp_image_select_polygon 似乎不起作用。

代码

这是我在 python 控制台中尝试做的事情的基本框架:



theImage = gimp.image_list()[0]
OP_ADD = 0
POINT_COUNT = 5
x = 0
y = 0
points = [0.0 for i in range(0,10)]
points[0] = 64.0 + (128.0 * x)
points[1] = 64.0 * y
points[2] = 128.0 * x
points[3] = 32.0 + (64.0 * y)
points[4] = 64.0 + (128.0 * x)
points[5] = 64.0 + (64.0 * y)
points[6] = 128.0 + (128.0 * x)
points[7] = 32.0 + (64.0 * y)
points[8] = 64.0 + (128.0 * x)
points[9] = 64.0 * y
pdb.gimp_image_select_polygon(theImage, OP_ADD, POINT_COUNT, points)

运行时,没有发生。 OTOH,如果我使用另一个选择功能,我会得到一个选择:



pdb.gimp_image_select_rectangle(theImage, 0, 64 ,0 ,128 ,32)

我在使用 gimp_image_select_polygon 时没有发现回溯错误,所以我知道我有正确数量的参数和正确的参数类型。我尝试了各种方法,但无法在网上找到太多帮助。

有没有人看到我的代码有问题,或者 GIMP 中的 python 引擎完全是胡说八道?

最佳答案

长度参数是坐标的数量,而不是点的数量(因此,通常是 double )

OP_REPLACE 在我的版本中没有定义。

对于 (100,100) 处的 100x100 正方形:

p=[100,100,100,200,200,200,200,100]
pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE,len(p),p)

关于selection - Gimp python-fu 如何选择多边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39641231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com