-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
98 lines (74 loc) · 3.31 KB
/
Copy pathutil.py
File metadata and controls
98 lines (74 loc) · 3.31 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import cv2 as cv
import streamlit as st
def detect(dataFrame, frame):
(w,h) = frame.shape[:2]
topLeft = []
topRight = []
bottomLeft = []
bottomRight = []
xCen, yCen = int(w//2), int(h//2)
# Display Back Canvas
frame[:] = (0,0,0)
# Display Grid
cv.line(frame, (0, int(w/2)), (h, int(w/2)), color=(199,21,133), thickness=10)
cv.line(frame, (int(h/2), 0), (int(h/2), w), color=(199,21,133), thickness=10)
for i in dataFrame.index:
if dataFrame["class"][i] == 1:
cv.rectangle(frame,(int(dataFrame["xmin"][i]),int(dataFrame["ymin"][i])),(int(dataFrame["xmax"][i]),int(dataFrame["ymax"][i])),(0,255,0),2)
cv.putText(frame, f'{i}', (int(dataFrame["xmin"][i]),int(dataFrame["ymin"][i])-10), cv.FONT_HERSHEY_SIMPLEX, 0.9, (0,255,0), 2)
x = int((int(dataFrame["xmin"][i]) + int(dataFrame["xmax"][i])) / 2)
y = int((int(dataFrame["ymin"][i]) + int(dataFrame["ymax"][i])) / 2)
cv.circle(frame, (x,y), radius=5, color=(0, 0, 255), thickness=-1)
else:
cv.rectangle(frame,(int(dataFrame["xmin"][i]),int(dataFrame["ymin"][i])),(int(dataFrame["xmax"][i]),int(dataFrame["ymax"][i])),(255,0,0),2)
cv.putText(frame, f'{i}', (int(dataFrame["xmin"][i]),int(dataFrame["ymin"][i])-10), cv.FONT_HERSHEY_SIMPLEX, 0.9, (255,0,0), 2)
x = int(int(dataFrame["xmin"][i]) + int(dataFrame["xmax"][i]) / 2)
y = int(int(dataFrame["ymin"][i]) + int(dataFrame["ymax"][i]) / 2)
cv.circle(frame, (x,y), radius=5, color=(0, 0, 255), thickness=-1)
if y > xCen:
if x < yCen:
try:
xPrev, yPrev = topLeft[-1]
cv.line(frame, (xPrev, yPrev), (x,y), color = (0, 0, 255), thickness=3)
except:
pass
topLeft.append((x,y))
else:
try:
xPrev, yPrev = topRight[-1]
cv.line(frame, (xPrev, yPrev), (x,y), color=(0, 0, 255), thickness=3)
except:
pass
topRight.append([x,y])
else:
if x < yCen:
try:
xPrev, yPrev = bottomLeft[-1]
cv.line(frame, (xPrev, yPrev), (x,y), color = (0, 0, 255), thickness=3)
except:
pass
bottomLeft.append((x,y))
else:
try:
xPrev, yPrev = bottomRight[-1]
cv.line(frame, (xPrev, yPrev), (x,y), color=(0, 0, 255), thickness=3)
except:
pass
bottomRight.append([x,y])
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
return frame
def framePerSecond(newTime, prvTime):
return 1/(newTime - prvTime)
def defaultConfig(pagesize:int=0):
if pagesize == 0:
st.set_page_config(layout="wide")
elif pagesize == 1:
st.set_page_config(layout="centered")
hide_st_style = """
<style>
MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)