Spaces:
Runtime error
Runtime error
new update
Browse files- Segmentation.py +8 -5
- app.py +6 -6
Segmentation.py
CHANGED
@@ -10,6 +10,7 @@ def black_mask(results):
|
|
10 |
if not os.path.exists(runs_folder):
|
11 |
# Nếu chưa tồn tại, tạo thư mục "mask"
|
12 |
os.makedirs(runs_folder)
|
|
|
13 |
for mask_index in range(len(results[0].masks)):
|
14 |
# Lấy mặt nạ
|
15 |
mask_raw = results[0].masks[mask_index].cpu().data.numpy().transpose(1, 2, 0)
|
@@ -34,9 +35,11 @@ def black_mask(results):
|
|
34 |
black_color = [0, 0, 0]
|
35 |
white_color = [255, 255, 255]
|
36 |
result_image = np.where(np.all(masked == black_color, axis=-1, keepdims=True), masked, white_color)
|
37 |
-
name = "mask/"+str(mask_index) + '.png'
|
38 |
-
# Show the masked part of the image
|
39 |
-
cv2.imwrite(name,result_image)
|
|
|
|
|
40 |
def segmentation_doc(image):
|
41 |
model = YOLO('Model/Seg65ep.pt')
|
42 |
runs_folder = "runs"
|
@@ -52,7 +55,7 @@ def segmentation_doc(image):
|
|
52 |
padding_size = 50
|
53 |
image = cv2.copyMakeBorder(image, padding_size, padding_size, padding_size, padding_size, cv2.BORDER_CONSTANT, value=color)
|
54 |
results = model(image,save=True,retina_masks = True, conf=0.7)
|
55 |
-
black_mask(results)
|
56 |
-
return image
|
57 |
# image=cv2.imread("test1.jpg")
|
58 |
# segmentation_doc(image)
|
|
|
10 |
if not os.path.exists(runs_folder):
|
11 |
# Nếu chưa tồn tại, tạo thư mục "mask"
|
12 |
os.makedirs(runs_folder)
|
13 |
+
bl_mask=[]
|
14 |
for mask_index in range(len(results[0].masks)):
|
15 |
# Lấy mặt nạ
|
16 |
mask_raw = results[0].masks[mask_index].cpu().data.numpy().transpose(1, 2, 0)
|
|
|
35 |
black_color = [0, 0, 0]
|
36 |
white_color = [255, 255, 255]
|
37 |
result_image = np.where(np.all(masked == black_color, axis=-1, keepdims=True), masked, white_color)
|
38 |
+
# name = "mask/"+str(mask_index) + '.png'
|
39 |
+
# # Show the masked part of the image
|
40 |
+
# cv2.imwrite(name,result_image)
|
41 |
+
bl_mask.append(result_image)
|
42 |
+
return bl_mask
|
43 |
def segmentation_doc(image):
|
44 |
model = YOLO('Model/Seg65ep.pt')
|
45 |
runs_folder = "runs"
|
|
|
55 |
padding_size = 50
|
56 |
image = cv2.copyMakeBorder(image, padding_size, padding_size, padding_size, padding_size, cv2.BORDER_CONSTANT, value=color)
|
57 |
results = model(image,save=True,retina_masks = True, conf=0.7)
|
58 |
+
bl_mask=black_mask(results)
|
59 |
+
return image,bl_mask
|
60 |
# image=cv2.imread("test1.jpg")
|
61 |
# segmentation_doc(image)
|
app.py
CHANGED
@@ -8,13 +8,13 @@ from Rotate.rotate_function import *
|
|
8 |
from Rotate import rotate_function
|
9 |
# from Restomer import *
|
10 |
def process_image(input_image):
|
11 |
-
original_img=segmentation_doc(input_image)
|
12 |
output_images=[]
|
13 |
-
mask_path="mask"
|
14 |
-
masks = [f for f in os.listdir(mask_path) if os.path.isfile(os.path.join(mask_path, f))]
|
15 |
-
for
|
16 |
-
mask=os.path.join(mask_path, mask_name)
|
17 |
-
mask_img=cv2.imread(mask)
|
18 |
extract_document=extract(original_img,mask_img)
|
19 |
# result=rotate_function.rotate(extract_document)
|
20 |
# result=run_script(result, 720, 32)
|
|
|
8 |
from Rotate import rotate_function
|
9 |
# from Restomer import *
|
10 |
def process_image(input_image):
|
11 |
+
original_img,masks=segmentation_doc(input_image)
|
12 |
output_images=[]
|
13 |
+
# mask_path="mask"
|
14 |
+
# masks = [f for f in os.listdir(mask_path) if os.path.isfile(os.path.join(mask_path, f))]
|
15 |
+
for mask_img in masks:
|
16 |
+
# mask=os.path.join(mask_path, mask_name)
|
17 |
+
# mask_img=cv2.imread(mask)
|
18 |
extract_document=extract(original_img,mask_img)
|
19 |
# result=rotate_function.rotate(extract_document)
|
20 |
# result=run_script(result, 720, 32)
|