11-06-2024, 05:57 PM
I queried Bing's Co-Pilot what tool and what code might serve to automate splitting an image into squares, this to conform to the format requirement of a cloud-based machine vision tool called Roboflow, which I'm intending to use to automate crack detection in concrete. (I've managed to learn enough about labelling in CVAT to download a json file containing the annotations in COCO 1.0, but am stuck attempting to train a model locally on my PC using detectron2.) To stay in motion while I await help on that, here's where I'm stuck using a Python-Fu script in Gimp.
When the code from Co-Pilot didn't produce anything, I asked it to simplify the operation to first confirm basic functionality using scripting in Gimp. It suggested creating a new file, but when that didn't produce anything, it further simplified to create a simple message, "Hello from Python-Fu". And when that only flashed the Console for a fraction of a sec, it included a prompt to pause for 10 seconds, which then at least that pause did work. That said, I'm not even seeing the pause when adding the create new image prompt:
from gimpfu import *
import time
def simple_message(image, drawable):
gimp.message("Hello from Python-Fu!")
time.sleep(10) # Pause for 10 seconds
def create_image(image, drawable):
save_dir = "D:/ALDOT_Model/Split_Test" # Change this to your desired directory
os.makedirs(save_dir, exist_ok=True)
# Create a new image
new_image = pdb.gimp_image_new(100, 100, RGB)
new_layer = pdb.gimp_layer_new(new_image, 100, 100, RGB_IMAGE, "New Layer", 100, NORMAL_MODE)
pdb.gimp_image_insert_layer(new_image, new_layer, None, -1)
pdb.gimp_image_flatten(new_image)
pdb.file_png_save(new_image, pdb.gimp_image_get_active_drawable(new_image), os.path.join(save_dir, "new_image.png"), "new_image.png", False, 9, True, True, True, True, True)
gimp.message("Created and saved a new image as new_image.png")
register(
"python_fu_create_image",
"Create a new image and save it",
"Create a new image and save it",
"Your Name",
"Your Name",
"2024",
"<Image>/Python-Fu/Create Image",
"*",
[],
[],
create_image)
main()
Many thanks for your insights!
When the code from Co-Pilot didn't produce anything, I asked it to simplify the operation to first confirm basic functionality using scripting in Gimp. It suggested creating a new file, but when that didn't produce anything, it further simplified to create a simple message, "Hello from Python-Fu". And when that only flashed the Console for a fraction of a sec, it included a prompt to pause for 10 seconds, which then at least that pause did work. That said, I'm not even seeing the pause when adding the create new image prompt:
from gimpfu import *
import time
def simple_message(image, drawable):
gimp.message("Hello from Python-Fu!")
time.sleep(10) # Pause for 10 seconds
def create_image(image, drawable):
save_dir = "D:/ALDOT_Model/Split_Test" # Change this to your desired directory
os.makedirs(save_dir, exist_ok=True)
# Create a new image
new_image = pdb.gimp_image_new(100, 100, RGB)
new_layer = pdb.gimp_layer_new(new_image, 100, 100, RGB_IMAGE, "New Layer", 100, NORMAL_MODE)
pdb.gimp_image_insert_layer(new_image, new_layer, None, -1)
pdb.gimp_image_flatten(new_image)
pdb.file_png_save(new_image, pdb.gimp_image_get_active_drawable(new_image), os.path.join(save_dir, "new_image.png"), "new_image.png", False, 9, True, True, True, True, True)
gimp.message("Created and saved a new image as new_image.png")
register(
"python_fu_create_image",
"Create a new image and save it",
"Create a new image and save it",
"Your Name",
"Your Name",
"2024",
"<Image>/Python-Fu/Create Image",
"*",
[],
[],
create_image)
main()
Many thanks for your insights!