Spaces:
Build error
Build error
Commit ·
e636319
0
Parent(s):
init
Browse files- app.py +40 -0
- examples/pipe-1-1.jpg +0 -0
- examples/pipe-1-2.jpg +0 -0
- requirements.txt +1 -0
- show-pipe.ipynb +0 -0
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import glob
|
| 2 |
+
|
| 3 |
+
import cv2 as cv
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
images = glob.glob("examples/*")
|
| 8 |
+
|
| 9 |
+
def findCircle(img_path: str, center):
|
| 10 |
+
source = cv.imread(img_path, cv.IMREAD_GRAYSCALE)
|
| 11 |
+
img = cv.medianBlur(source,5)
|
| 12 |
+
color_img = cv.imread(img_path)
|
| 13 |
+
|
| 14 |
+
circles = cv.HoughCircles(img,cv.HOUGH_GRADIENT,1,minDist=20,
|
| 15 |
+
param1=50,param2=30,minRadius=10,maxRadius=28)
|
| 16 |
+
circles = np.uint16(np.around(circles))
|
| 17 |
+
for i in circles[0,:]:
|
| 18 |
+
if abs(center[0] - i[0]) < 20 \
|
| 19 |
+
and abs(center[1] - i[1]) < 20:
|
| 20 |
+
# draw the outer circle
|
| 21 |
+
cv.circle(color_img,(i[0],i[1]),i[2],(0,255,0),2)
|
| 22 |
+
# draw the center of the circle
|
| 23 |
+
cv.circle(color_img,(i[0],i[1]),2,(0,0,255),3)
|
| 24 |
+
# bgr to rgb
|
| 25 |
+
return color_img[:, :, ::-1]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
with gr.Blocks() as demo:
|
| 29 |
+
with gr.Row():
|
| 30 |
+
input_img = gr.Image(images[0], type='filepath', label="Input")
|
| 31 |
+
output_img = gr.Image(label="Selected Segment")
|
| 32 |
+
|
| 33 |
+
def get_select_coords(img, evt: gr.SelectData):
|
| 34 |
+
position = (evt.index[0], evt.index[1])
|
| 35 |
+
return findCircle(img, position)
|
| 36 |
+
|
| 37 |
+
input_img.select(get_select_coords, [input_img], output_img)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
demo.launch()
|
examples/pipe-1-1.jpg
ADDED
|
examples/pipe-1-2.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
opencv-python
|
show-pipe.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|