1
我想在將圖像發送到Tesseract進行OCR之前處理圖像。我可以爲GIMP創建一個腳本來執行多個過程嗎?
例如:
- 調整圖像
- 更改分辨率爲300 dpi
- 閾值(B &用黑白)
- 銳化圖像
我如何可以自動這個流程?
我想在將圖像發送到Tesseract進行OCR之前處理圖像。我可以爲GIMP創建一個腳本來執行多個過程嗎?
例如:
我如何可以自動這個流程?
我剛剛在平面設計上提供了一個答案(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
- 它幾乎相同,但有一個「應用」按鈕,可以方便地測試呼叫,並將其複製到插件代碼中。
可以在GIMP中完成嗎?是的 - 但是他們可能是一個更合適的自動化庫,它們是Leptonica或VIPS,甚至GEGL--都有Python綁定 - 這應該是你選擇的語言(即使你選擇GIMP,Python-fu會比腳本更好-fu,除非你已經知道方案) – jsbueno
如何在Python-fu中爲GIMP編寫腳本? –