简体   繁体   English

Gimp使用python选择区域坐标

[英]Gimp selected area coordinates with python

I want to get selected area px coordinates of an image. 我想获取图像的选定区域px坐标。 I use gimp and can i see that on the python fu console as real time debugging ? 我使用gimp,可以在python fu控制台上看到它作为实时调试吗?

I'm planning to free select some area on picture and i want to learn it on console. 我打算自由选择图片上的某些区域,我想在控制台上学习。 Which coordinates are in that selected area ? 在所选区域中哪些坐标?

First of all, when in Python concole, you have to geta reference to the working image - the easier way to get that is to call gimp.image_list() - this present you with a list of the open images in the reversed order they appear on the tabs in the "single window" mode. 首先,在Python conque中,您必须获取对工作图像的引用-更简单的方法是调用gimp.image_list()-这会向您显示打开图像的列表,它们以相反的顺序出现在“单个窗口”模式下的标签上。 So, to get the last oppened image, you can type: 因此,要获取最后一张图片,您可以输入:

 image = gimp.image_list()[0]

(and press <enter> ) If you type "image" and presse , you will inspect its contents - Python will display the standard representation of an Image object: <gimp.Image '[Untitled]'> - now, this image object, and its layers (which Pyton exposes in the as a list on the image.layers attribute) can be passed as parameters to hundreds of functions you can easily search if you press the browse button on the bottom of the dialog. (然后按<enter> ),如果您键入“ image”并按,则将检查其内容<gimp.Image '[Untitled]'>将显示Image对象的标准表示形式: <gimp.Image '[Untitled]'> -现在,此image对象,它的图层(Pyton在image.layers属性中以列表形式在pyton中公开)可以作为参数传递给数百个函数,如果您按下对话框底部的browse按钮,则可以轻松地进行搜索。 After finding the wanted method, just click on apply on the PDB browsing dialog, and the function and its needed parameters will be pasted on the Python prompt -if needed, edit the parameters to fit your needs, and call it by pressing ; 找到想要的方式后,只需点击apply上的PDB浏览对话框,并且功能和它需要的参数将在需要Python的提示-如果粘贴,编辑参数,以满足您的需求,并通过按调用它; In this case you want to call ("gimp_get_selection_bounds"): 在这种情况下,您要致电(“ gimp_get_selection_bounds”):

>>> non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)

And your wanted values are now in the variables x1, y1, x2 and y2. 现在,所需的值在变量x1,y1,x2和y2中。 If you want just to display them, delete the command up to the pdb and the returned values will be just printed. 如果只想显示它们,则删除命令直到pdb ,返回的值将被打印出来。

If you will work on this often, it will be seriously usefull to learn a little of Python - the tutorial on the http://python.org site will be able to help you a lot. 如果你将在这个经常加班,将会受到严重有用的学习一点的Python -上教程http://python.org网站将能够帮助你很多。

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

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