3

问题

我需要对图像进行数百次多边形选择。为了提供帮助,我一直在尝试使用 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 引擎完全没有问题?

4

1 回答 1

4

长度参数是坐标数,而不是点数(因此,通常是双精度数)

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)
于 2016-09-23T06:44:38.477 回答