Spaces:
Runtime error
Runtime error
File size: 2,140 Bytes
fb41312 88de542 390ad5b 85df948 d8fbaf2 4a0cbf8 fb41312 6aa96a4 88de542 fb41312 88de542 c706d22 90c0555 038e67f 390ad5b 038e67f 390ad5b 9f54a3d af0f82d 390ad5b 88de542 01763a3 390ad5b bd6297f 03cc5b5 452e6a8 71d2f0c 99c5a26 71d2f0c a1ed5cd e65e092 71d2f0c fb41312 a0c0e90 882e081 d041661 c70d8ad d8fbaf2 fb41312 4d327e3 bd6297f bb6f75b ff771ad 008f257 88de542 bcfe357 362f9c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import gradio as gr
import cv2
import json
import numpy as np
import glob2 as glob
from PIL import Image
from pyAAMED import pyAAMED
title = """
<h1>Arc Adjacency Matrix based Fast Ellipse Detection</h1>
<a href="https://github.com/Li-Zhaoxi/AAMED">Gitub</a>
"""
def detect_ellipses(img_path):
imgC = cv2.imread(img_path)
imgG = cv2.cvtColor(imgC, cv2.COLOR_BGR2GRAY)
ammed_size = 600
iheight, iwidth = imgG.shape
imax = max(iheight, iwidth)
iscale = (ammed_size - 1) / imax
is_landscape = iwidth >= iheight
if is_landscape:
iw = imax * iscale
ih = iheight * iscale
else:
iw = iwidth * iscale
ih = imax * iscale
imgG = cv2.resize(imgG, (int(iw), int(ih)))
aamed = pyAAMED(ammed_size, ammed_size)
aamed.setParameters(3.1415926/3, 3.4, 0.77)
print(ammed_size, iw, ih, imgG.shape)
result = aamed.run_AAMED(imgG)
imgN = imgG.copy()
if len(result) > 0:
imgN = cv2.cvtColor(imgN, cv2.COLOR_GRAY2RGB)
for e in result:
x, y, w, h, a, _ = e
imgN = cv2.ellipse(imgN, (y, x), (int(h / 2), int(w / 2)), -a, 0, 360, (0, 255, 0), 3) # image, center_coordinates, axesLength, angle, startAngle, endAngle, color, thickness
# from CPP code:
# temp.center.x = detEllipses[i].center.y;
# temp.center.y = detEllipses[i].center.x;
# temp.size.height = detEllipses[i].size.width;
# temp.size.width = detEllipses[i].size.height;
# temp.angle = -detEllipses[i].angle;
return [Image.fromarray(imgN), json.dumps(result.tolist())]
examples = []
test_files = glob.glob('./examples/*.jpg') + glob.glob('./examples/*.png')
for f in test_files:
examples = examples + [[f]]
gr.Interface(
fn=detect_ellipses,
inputs=gr.Image(label="Upload image with ellipses", type="filepath"),
outputs=[
gr.Image(type="pil", label="Detected ellipses"),
gr.Textbox(label="Detected ellipses")
],
title=title,
examples=examples,
allow_flagging='never'
).launch(
debug=True,
server_name="0.0.0.0",
server_port=7860
) |