Spaces:
Runtime error
Runtime error
new update
Browse filesFiles changed (2)
- Segmentation.py+8-5
- app.py+6-6
9 unmodified lines10111213141518 unmodified lines3435363738394041429 unmodified lines525354555657589 unmodified linesif not os.path.exists(runs_folder):# Nếu chưa tồn tại, tạo thư mục "mask"os.makedirs(runs_folder)for mask_index in range(len(results[0].masks)):# Lấy mặt nạmask_raw = results[0].masks[mask_index].cpu().data.numpy().transpose(1, 2, 0)18 unmodified linesblack_color = [0, 0, 0]white_color = [255, 255, 255]result_image = np.where(np.all(masked == black_color, axis=-1, keepdims=True), masked, white_color)name = "mask/"+str(mask_index) + '.png'# Show the masked part of the imagecv2.imwrite(name,result_image)def segmentation_doc(image):model = YOLO('Model/Seg65ep.pt')runs_folder = "runs"9 unmodified linespadding_size = 50image = cv2.copyMakeBorder(image, padding_size, padding_size, padding_size, padding_size, cv2.BORDER_CONSTANT, value=color)results = model(image,save=True,retina_masks = True, conf=0.7)black_mask(results)return image# image=cv2.imread("test1.jpg")# segmentation_doc(image)9 unmodified lines1011121314151618 unmodified lines35363738394041424344459 unmodified lines555657585960619 unmodified linesif not os.path.exists(runs_folder):# Nếu chưa tồn tại, tạo thư mục "mask"os.makedirs(runs_folder)bl_mask=[]for mask_index in range(len(results[0].masks)):# Lấy mặt nạmask_raw = results[0].masks[mask_index].cpu().data.numpy().transpose(1, 2, 0)18 unmodified linesblack_color = [0, 0, 0]white_color = [255, 255, 255]result_image = np.where(np.all(masked == black_color, axis=-1, keepdims=True), masked, white_color)# name = "mask/"+str(mask_index) + '.png'# # Show the masked part of the image# cv2.imwrite(name,result_image)bl_mask.append(result_image)return bl_maskdef segmentation_doc(image):model = YOLO('Model/Seg65ep.pt')runs_folder = "runs"9 unmodified linespadding_size = 50image = cv2.copyMakeBorder(image, padding_size, padding_size, padding_size, padding_size, cv2.BORDER_CONSTANT, value=color)results = model(image,save=True,retina_masks = True, conf=0.7)bl_mask=black_mask(results)return image,bl_mask# image=cv2.imread("test1.jpg")# segmentation_doc(image)
7 unmodified lines8910111213141516171819207 unmodified linesfrom Rotate import rotate_function# from Restomer import *def process_image(input_image):original_img=segmentation_doc(input_image)output_images=[]mask_path="mask"masks = [f for f in os.listdir(mask_path) if os.path.isfile(os.path.join(mask_path, f))]for mask_name in masks:mask=os.path.join(mask_path, mask_name)mask_img=cv2.imread(mask)extract_document=extract(original_img,mask_img)# result=rotate_function.rotate(extract_document)# result=run_script(result, 720, 32)7 unmodified lines8910111213141516171819207 unmodified linesfrom Rotate import rotate_function# from Restomer import *def process_image(input_image):original_img,masks=segmentation_doc(input_image)output_images=[]# mask_path="mask"# masks = [f for f in os.listdir(mask_path) if os.path.isfile(os.path.join(mask_path, f))]for mask_img in masks:# mask=os.path.join(mask_path, mask_name)# mask_img=cv2.imread(mask)extract_document=extract(original_img,mask_img)# result=rotate_function.rotate(extract_document)# result=run_script(result, 720, 32)
Segmentation.py+8-5
app.py+6-6