Spaces:
Running
Running
Gerold Meisinger commited on
Commit ·
5e568dc
1
Parent(s): f77a55c
fixed output size to mod64, added examples
Browse files- .gitignore +3 -0
- README.md +1 -1
- app.py +36 -3
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
flagged
|
| 3 |
+
|
README.md
CHANGED
|
@@ -7,7 +7,7 @@ sdk: gradio
|
|
| 7 |
sdk_version: 3.44.4
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
license:
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 7 |
sdk_version: 3.44.4
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: agpl-3.0
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -1,19 +1,52 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
|
|
|
| 3 |
|
| 4 |
ed = cv2.ximgproc.createEdgeDrawing()
|
| 5 |
params = cv2.ximgproc.EdgeDrawing.Params()
|
| 6 |
params.PFmode = True
|
| 7 |
ed.setParams(params)
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def edpf(image_rgb):
|
| 10 |
img_gray = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY)
|
| 11 |
-
|
|
|
|
| 12 |
edge_map = ed.getEdgeImage(edges)
|
| 13 |
return edge_map
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
if __name__ == "__main__":
|
| 18 |
-
|
| 19 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
ed = cv2.ximgproc.createEdgeDrawing()
|
| 6 |
params = cv2.ximgproc.EdgeDrawing.Params()
|
| 7 |
params.PFmode = True
|
| 8 |
ed.setParams(params)
|
| 9 |
|
| 10 |
+
def center_crop_mod64(img):
|
| 11 |
+
h, w = img.shape[:2]
|
| 12 |
+
shortside, longside = min(w, h), max(w, h)
|
| 13 |
+
longside_crop = (longside // 64) * 64
|
| 14 |
+
left = (w - longside_crop) // 2 if w > h else 0
|
| 15 |
+
top = (h - longside_crop) // 2 if h > w else 0
|
| 16 |
+
right = left + longside_crop if w > h else shortside
|
| 17 |
+
bottom = top + longside_crop if h > w else shortside
|
| 18 |
+
return img[top:bottom, left:right]
|
| 19 |
+
|
| 20 |
def edpf(image_rgb):
|
| 21 |
img_gray = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY)
|
| 22 |
+
img_crop = center_crop_mod64(img_gray)
|
| 23 |
+
edges = ed.detectEdges(img_crop)
|
| 24 |
edge_map = ed.getEdgeImage(edges)
|
| 25 |
return edge_map
|
| 26 |
|
| 27 |
+
examples=[
|
| 28 |
+
os.path.join(os.path.dirname(__file__), "images/bag.png"),
|
| 29 |
+
os.path.join(os.path.dirname(__file__), "images/beard.png"),
|
| 30 |
+
os.path.join(os.path.dirname(__file__), "images/bird.png"),
|
| 31 |
+
os.path.join(os.path.dirname(__file__), "images/cat.png"),
|
| 32 |
+
os.path.join(os.path.dirname(__file__), "images/dog2.png"),
|
| 33 |
+
os.path.join(os.path.dirname(__file__), "images/house.png"),
|
| 34 |
+
os.path.join(os.path.dirname(__file__), "images/house2.png"),
|
| 35 |
+
os.path.join(os.path.dirname(__file__), "images/human.png"),
|
| 36 |
+
os.path.join(os.path.dirname(__file__), "images/kitten.png"),
|
| 37 |
+
os.path.join(os.path.dirname(__file__), "images/lion.png"),
|
| 38 |
+
os.path.join(os.path.dirname(__file__), "images/man.png"),
|
| 39 |
+
os.path.join(os.path.dirname(__file__), "images/robot.png"),
|
| 40 |
+
os.path.join(os.path.dirname(__file__), "images/robotics.png"),
|
| 41 |
+
os.path.join(os.path.dirname(__file__), "images/room.png"),
|
| 42 |
+
os.path.join(os.path.dirname(__file__), "images/room2.png"),
|
| 43 |
+
os.path.join(os.path.dirname(__file__), "images/suit.png"),
|
| 44 |
+
os.path.join(os.path.dirname(__file__), "images/tree.png"),
|
| 45 |
+
os.path.join(os.path.dirname(__file__), "images/vermeer.png"),
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
app = gr.Interface(fn=edpf, inputs=gr.Image(value="images/dog2.png"), outputs="image", title="Edge Drawing Parameter Free", description="A modern edge detection algorithm which requires no parameter tuning. Generate edge maps for the edpf ControlNet model at https://huggingface.co/GeroldMeisinger/control-edgedrawing", examples=examples)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
+
app.launch()
|
| 52 |
|