vvims / test.py
Ntchinda-Giscard's picture
add roboflow
d2d3d7a
# import tempfile
# from roboflow import Roboflow
# from PIL import Image
# import json
# def set_image_dpi(file_path):
# im = Image.open(file_path)
# length_x, width_y = im.size
# factor = min(1, float(1024.0 / length_x))
# size = int(factor * length_x), int(factor * width_y)
# im_resized = im.resize(size, Image.LANCZOS)
# temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
# i = 0
# i =+ 1
# temp_filename = f'enhanced{i}.jpg'
# im_resized.save(temp_filename, dpi=(300, 300))
# return temp_filename
# def crop_images_from_detections(detections):
# for detection in detections:
# image_path = detection["image_path"]
# image = Image.open(image_path)
# x1 = detection['x'] - detection['width'] / 2
# x2 = detection['x'] + detection['width'] / 2
# y1 = detection['y'] - detection['height'] / 2
# y2 = detection['y'] + detection['height'] / 2
# box = (x1, y1, x2, y2)
# cropped_image = image.crop(box)
# path= f"{detection['class']}.jpg"
# cropped_image.save(path) # Or save the image using cropped_image.save('path_to_save_image')
# set_image_dpi(path)
# rf = Roboflow(api_key="P4usj8uPwcbnflvyJIAB")
# project = rf.workspace("ntchindagiscard").project("id_card_annotation")
# model = project.version(1).model
# model.predict("2ed1bdb5-5c09-40a0-a39f-9ff6c15380bf-front.jpg", confidence=20, overlap=50).save('prediction.jpg')
# result = model.predict("2ed1bdb5-5c09-40a0-a39f-9ff6c15380bf-front.jpg", confidence=20, overlap=50)
# crop_images_from_detections(result)
# print(result)