Spaces:
Runtime error
Runtime error
Commit
•
224c718
1
Parent(s):
ce75465
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,13 @@ import numpy as np
|
|
11 |
|
12 |
torch.hub.download_url_to_file('https://i.pinimg.com/originals/45/d0/30/45d03054e15f4be731781eecba7458a4.jpg', 'korean.jpg')
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def midpoint(x1, y1, x2, y2):
|
15 |
x_mid = int((x1 + x2)/2)
|
16 |
y_mid = int((y1 + y2)/2)
|
@@ -39,6 +46,10 @@ def inference(img, lang):
|
|
39 |
reader = easyocr.Reader(lang)
|
40 |
bounds = reader.readtext(img.name)
|
41 |
im = PIL.Image.open(img.name)
|
|
|
|
|
|
|
|
|
42 |
#mask = PIL.Image.open(img.name)
|
43 |
mask = Image.new("L", im.size, 0)
|
44 |
draw_mask(mask, bounds)
|
@@ -51,17 +62,16 @@ def inference(img, lang):
|
|
51 |
im.save('result.jpg')
|
52 |
mask.save('mask.png')
|
53 |
|
54 |
-
img = cv.imread('result.jpg')
|
55 |
-
mask = cv.imread('mask2.png',0)
|
56 |
-
dst = cv.inpaint(img,mask,3,cv.INPAINT_TELEA)
|
57 |
-
|
58 |
|
59 |
#final.save('final.png')
|
60 |
#img_inpainted.save('inpaint.jpg')
|
61 |
#dst = cv2.inpaint(np.float32(img),np.float32(mask),3,cv2.INPAINT_TELEA)
|
62 |
#img_inpainted = cv2.inpaint(im, mask, 7, cv2.INPAINT_TELEA)
|
63 |
#cv2.imwrite('dst.png', dst)
|
64 |
-
|
65 |
return ['result.jpg', 'mask.png', pd.DataFrame(bounds). iloc[: , 1:2]]
|
66 |
|
67 |
title = 'EasyOCR'
|
|
|
11 |
|
12 |
torch.hub.download_url_to_file('https://i.pinimg.com/originals/45/d0/30/45d03054e15f4be731781eecba7458a4.jpg', 'korean.jpg')
|
13 |
|
14 |
+
def convert(img):
|
15 |
+
pil_im = Image.fromarray(image)
|
16 |
+
b = io.BytesIO()
|
17 |
+
pil_im.save(b, 'jpeg')
|
18 |
+
im_bytes = b.getvalue()
|
19 |
+
return im_bytes
|
20 |
+
|
21 |
def midpoint(x1, y1, x2, y2):
|
22 |
x_mid = int((x1 + x2)/2)
|
23 |
y_mid = int((y1 + y2)/2)
|
|
|
46 |
reader = easyocr.Reader(lang)
|
47 |
bounds = reader.readtext(img.name)
|
48 |
im = PIL.Image.open(img.name)
|
49 |
+
|
50 |
+
byte_img = convert(im)
|
51 |
+
img_array = np.array(Image.open(io.BytesIO(byte_img)))
|
52 |
+
|
53 |
#mask = PIL.Image.open(img.name)
|
54 |
mask = Image.new("L", im.size, 0)
|
55 |
draw_mask(mask, bounds)
|
|
|
62 |
im.save('result.jpg')
|
63 |
mask.save('mask.png')
|
64 |
|
65 |
+
#img = cv.imread('result.jpg')
|
66 |
+
#mask = cv.imread('mask2.png',0)
|
67 |
+
#dst = cv.inpaint(img,mask,3,cv.INPAINT_TELEA)
|
|
|
68 |
|
69 |
#final.save('final.png')
|
70 |
#img_inpainted.save('inpaint.jpg')
|
71 |
#dst = cv2.inpaint(np.float32(img),np.float32(mask),3,cv2.INPAINT_TELEA)
|
72 |
#img_inpainted = cv2.inpaint(im, mask, 7, cv2.INPAINT_TELEA)
|
73 |
#cv2.imwrite('dst.png', dst)
|
74 |
+
#cv.imwrite('result.jpg',dst)
|
75 |
return ['result.jpg', 'mask.png', pd.DataFrame(bounds). iloc[: , 1:2]]
|
76 |
|
77 |
title = 'EasyOCR'
|