2015-05-18 30 views
1

我想在将图像发送到Tesseract进行OCR之前处理图像。我可以为GIMP创建一个脚本来执行多个过程吗?

例如:

  • 调整图像
  • 更改分辨率为300 dpi
  • 阈值(B &用黑白)
  • 锐化图像

我如何可以自动这个流程?

+0

可以在GIMP中完成吗?是的 - 但是他们可能是一个更合适的自动化库,它们是Leptonica或VIPS,甚至GEGL--都有Python绑定 - 这应该是你选择的语言(即使你选择GIMP,Python-fu会比脚本更好-fu,除非你已经知道方案) – jsbueno

+0

如何在Python-fu中为GIMP编写脚本? –

回答

1

我刚刚在平面设计上提供了一个答案(https://graphicdesign.stackexchange.com/questions/53919/editing-several-hundred-images-gimp/53965#53965),该平面设计旨在作为面向没有编程技能的人员的GIMP自动化入门 - 对于理解Python-fu也应该很好。

在同样的答案中,有官方文档的链接,以及如何创建小脚本的一个示例。他们应该让GIMP的PDB找到你想要的确切收益。

但是,这一切的一切,你可以创建一个Python文件是这样的:

from gimpfu import * 
import glob 

def auto(): 
    for filename in glob(source_folder + "/*.png"): 
     img = pdb.gimp_file_load(source_folder + filename, source_folder + filename) 
     # place the PDB calls to draw on the image before your interation here 

     #disp = pdb.gimp_display_new(img) 

     pdb.gimp_image_merge_visible_layers(img, CLIP_TO_IMAGE) 
     pdb.gimp_file_save(img, img.layers[0], dest_folder + filename, dest_folder + filename) 
     # pdb.gimp_display_delete(disp) 
     pdb.gimp_image_delete(img) # drops the image from gimp memory 


register("batch_process_for_blah", 
     "<short dexcription >Batch Process for Bla", 
     "<Extended description text>", 
     "author name", 
     "license text", 
     "copyright note", 
     "menu label for plug-in", 
     "", # image types for which the plug-in apply - "*" for all, blank for plug-in that opens image itself 
     [(PF_DIRNAME, "source_folder", "Source Folder", None), 
      (PF_DIRNAME, "dest_folder", "Dest Folder", None)], # input parameters - 
     [], # output parameters 
     menu="<Image>/File", # location of the entry on the menus 
     ) 
main() 

要找到for循环中想要的操作,转到Help->Procedure Browser - 或更好,但Filters->Python->Console和命中Browse - 它几乎相同,但有一个“应用”按钮,可以方便地测试呼叫,并将其复制到插件代码中。

相关问题