Spaces:
Sleeping
Sleeping
Commit
·
80f1239
1
Parent(s):
c40efb3
working locally
Browse files- app.py +56 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
#from aruco_detector import ArucoDetector
|
3 |
+
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import os
|
7 |
+
|
8 |
+
dict_list = ['DICT_4X4_50', 'DICT_4X4_100', 'DICT_4X4_250', 'DICT_4X4_1000', 'DICT_5X5_50', 'DICT_5X5_100', 'DICT_5X5_250', 'DICT_5X5_1000', 'DICT_6X6_50', 'DICT_6X6_100', 'DICT_6X6_250', 'DICT_6X6_1000', 'DICT_7X7_50', 'DICT_7X7_100', 'DICT_7X7_250', 'DICT_7X7_1000', 'DICT_ARUCO_ORIGINAL', 'DICT_APRILTAG_16h5', 'DICT_APRILTAG_25h9', 'DICT_APRILTAG_36h10', 'DICT_APRILTAG_36h11']
|
9 |
+
|
10 |
+
def inference(image_path, dict_name):
|
11 |
+
if not dict_name:
|
12 |
+
raise gr.Error("No model selected. Please select a model.")
|
13 |
+
if not image_path:
|
14 |
+
raise gr.Error("No image provided. Please upload an image.")
|
15 |
+
|
16 |
+
dict_index = dict_list.index(dict_name)
|
17 |
+
aruco_dict = cv2.aruco.getPredefinedDictionary(dict_index)
|
18 |
+
|
19 |
+
aruco_params = cv2.aruco.DetectorParameters()
|
20 |
+
detector = cv2.aruco.ArucoDetector(aruco_dict, aruco_params)
|
21 |
+
image = cv2.imread(image_path)
|
22 |
+
|
23 |
+
corners, ids, rejectedImgPoints = detector.detectMarkers(image)
|
24 |
+
image = cv2.aruco.drawDetectedMarkers(image, corners, ids, borderColor=(0, 255, 0))
|
25 |
+
for corner in corners:
|
26 |
+
cv2.polylines(image, [corner.astype(int)], isClosed=True, color=(0, 255, 0), thickness=3)
|
27 |
+
cv2.imwrite("output.jpg", image)
|
28 |
+
output_image = cv2.cvtColor(cv2.imread("output.jpg"), cv2.COLOR_BGR2RGB)
|
29 |
+
|
30 |
+
return output_image
|
31 |
+
|
32 |
+
def get_aruco_dict():
|
33 |
+
#PREDEFINED_DICTIONARY_NAME
|
34 |
+
return dict_list
|
35 |
+
|
36 |
+
aruco_dict = get_aruco_dict()
|
37 |
+
|
38 |
+
image_paths= [['examples/cans.png', 'DICT_4X4_50', 0.5],
|
39 |
+
['examples/image4k.png', 'DICT_4X4_50', 0.5],
|
40 |
+
]
|
41 |
+
|
42 |
+
demo = gr.Interface(
|
43 |
+
fn=inference,
|
44 |
+
inputs=[
|
45 |
+
gr.Image(type="filepath", label="Upload Image"),
|
46 |
+
gr.Dropdown(choices=aruco_dict, label="Select aruco library"),
|
47 |
+
|
48 |
+
],
|
49 |
+
outputs=gr.Image(type="numpy", label="Output Image"),
|
50 |
+
title="Aruco tag detection",
|
51 |
+
description="Select the aruco library, upload an image, and detect the aruco tags.",
|
52 |
+
examples=image_paths,
|
53 |
+
# flagging_mode="auto"
|
54 |
+
)
|
55 |
+
|
56 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
torchvision
|
4 |
+
Pillow
|
5 |
+
opencv-python
|
6 |
+
numpy
|
7 |
+
matplotlib
|