Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
blimp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aaron John Sabu
blimp
Commits
f1caaba6
Commit
f1caaba6
authored
3 years ago
by
Zhiying Li
Browse files
Options
Downloads
Plain Diff
Merge corrections
parents
db4a9b95
3811b48a
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ESP32_AT/imageTread_AT.py
+34
-14
34 additions, 14 deletions
ESP32_AT/imageTread_AT.py
ball_detection/ball_detection.py
+30
-30
30 additions, 30 deletions
ball_detection/ball_detection.py
with
64 additions
and
44 deletions
ESP32_AT/imageTread_AT.py
+
34
−
14
View file @
f1caaba6
...
...
@@ -21,19 +21,15 @@ def get_AT_6DOF_info(url, detectFlag = True):
header
=
{
"
User-Agent
"
:
"
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36.
"
}
req
=
Request
(
url
,
headers
=
header
)
img_resp
=
urlopen
(
req
,
timeout
=
60
)
# try:
#
# except:
# print ("April Tag Camera ERR",err)
# return tid,tx,ty,tz,rx,ry,rz
imgnp
=
np
.
array
(
bytearray
(
img_resp
.
read
()),
dtype
=
np
.
uint8
)
req
=
Request
(
url
,
headers
=
header
)
try
:
img_resp
=
urlopen
(
req
,
timeout
=
60
)
imgnp
=
np
.
array
(
bytearray
(
img_resp
.
read
()),
dtype
=
np
.
uint8
)
except
:
print
(
"
April Tag Camera NOT RUNNING
"
)
return
tid
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
frame
=
cv2
.
imdecode
(
imgnp
,
-
1
)
# ret,frame = cap.read()
gray_image
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
h
,
w
,
_
=
frame
.
shape
...
...
@@ -82,6 +78,7 @@ def get_AT_6DOF_info(url, detectFlag = True):
cv2
.
line
(
frame
,
ptD
,
ptA
,
(
0
,
255
,
0
),
5
)
<<<<<<<
HEAD
# extract the bounding box (x, y)-coordinates for the AprilTag
# and convert each of the (x, y)-coordinate pairs to integers
...
...
@@ -99,6 +96,32 @@ def get_AT_6DOF_info(url, detectFlag = True):
cv2
.
putText
(
frame
,
"
tx: {:.2f} ty: {:.2f} tz:{:.2f}
"
.
format
(
tx
[
0
],
ty
[
0
],
tz
[
0
]),
(
ptA
[
0
],
ptA
[
1
]
+
30
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
255
,
0
),
2
)
=======
# extract the bounding box (x, y)-coordinates for the AprilTag
# and convert each of the (x, y)-coordinate pairs to integers
(
ptA
,
ptB
,
ptC
,
ptD
)
=
r
.
corners
ptB
=
(
int
(
ptB
[
0
]),
int
(
ptB
[
1
]))
ptC
=
(
int
(
ptC
[
0
]),
int
(
ptC
[
1
]))
ptD
=
(
int
(
ptD
[
0
]),
int
(
ptD
[
1
]))
ptA
=
(
int
(
ptA
[
0
]),
int
(
ptA
[
1
]))
# draw the bounding box of the AprilTag detection
cv2
.
line
(
frame
,
ptA
,
ptB
,
(
0
,
255
,
0
),
5
)
cv2
.
line
(
frame
,
ptB
,
ptC
,
(
0
,
255
,
0
),
5
)
cv2
.
line
(
frame
,
ptC
,
ptD
,
(
0
,
255
,
0
),
5
)
cv2
.
line
(
frame
,
ptD
,
ptA
,
(
0
,
255
,
0
),
5
)
# draw the center (x, y)-coordinates of the AprilTag
(
cX
,
cY
)
=
(
int
(
r
.
center
[
0
]),
int
(
r
.
center
[
1
]))
cv2
.
circle
(
frame
,
(
cX
,
cY
),
5
,
(
0
,
0
,
255
),
-
1
)
# draw the tag family on the image
tagFamily
=
r
.
tag_family
.
decode
(
"
utf-8
"
)
#cv2.putText(frame, tagFamily, (ptA[0], ptA[1] - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
#cv2.putText(frame, "tx: {:.2f} ty: {:.2f} tz:{:.2f}".format(tx[0], ty[0], tz[0]), (ptA[0], ptA[1] + 30),
#cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
>>>>>>>
espcam
-
reconnect
if
debug_print
==
1
:
print
(
"
tx,ty,tz:{},{},{}
"
.
format
(
tx
,
ty
,
tz
))
...
...
@@ -135,10 +158,7 @@ if __name__ == "__main__":
url
=
'
http://10.0.0.6/cam-hi.jpg
'
#02
url
=
'
http://10.0.0.7/cam-hi.jpg
'
#06
# cv2.namedWindow("live transmission", cv2.WINDOW_AUTOSIZE)
# cv2.namedWindow("live transmission", cv2.WINDOW_NORMAL)
detector
=
Detector
()
...
...
This diff is collapsed.
Click to expand it.
ball_detection/ball_detection.py
+
30
−
30
View file @
f1caaba6
...
...
@@ -99,44 +99,44 @@ def detectLive(url , model, minDetectionScore = 0.90, showSight = True):
dist
=
-
1
header
=
{
"
User-Agent
"
:
"
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36.
"
}
req
=
Request
(
url
,
headers
=
header
)
img_resp
=
urlopen
(
req
,
timeout
=
60
)
imgnp
=
np
.
array
(
bytearray
(
img_resp
.
read
()),
dtype
=
np
.
uint8
)
frame
=
cv2
.
imdecode
(
imgnp
,
-
1
)
# try:
#
# except:
#
print ("Green Ball Camera ERR ",err)
# return gbx, gby, dist
req
=
Request
(
url
,
headers
=
header
)
try
:
img_resp
=
urlopen
(
req
,
timeout
=
60
)
imgnp
=
np
.
array
(
bytearray
(
img_resp
.
read
()),
dtype
=
np
.
uint8
)
except
:
print
(
"
Green Ball Camera NOT RUNNING
"
)
return
gbx
,
gby
,
dist
frame
=
cv2
.
imdecode
(
imgnp
,
-
1
)
labels
,
boxes
,
scores
=
model
.
predict
(
frame
)
for
i
in
range
(
boxes
.
shape
[
0
]):
box
=
boxes
[
i
]
x0
,
y0
=
float
(
box
[
0
]),
float
(
box
[
1
])
x1
,
y1
=
float
(
box
[
2
]),
float
(
box
[
3
])
w
=
x1
-
x0
h
=
y1
-
y0
dCrop
=
[
int
(
y0
*
cropFactor
+
y1
*
(
1
-
cropFactor
)),
int
(
y1
*
cropFactor
+
y0
*
(
1
-
cropFactor
)),
box
=
boxes
[
i
]
x0
,
y0
=
float
(
box
[
0
]),
float
(
box
[
1
])
x1
,
y1
=
float
(
box
[
2
]),
float
(
box
[
3
])
w
=
x1
-
x0
h
=
y1
-
y0
dCrop
=
[
int
(
y0
*
cropFactor
+
y1
*
(
1
-
cropFactor
)),
int
(
y1
*
cropFactor
+
y0
*
(
1
-
cropFactor
)),
int
(
x0
*
cropFactor
+
x1
*
(
1
-
cropFactor
)),
int
(
x1
*
cropFactor
+
x0
*
(
1
-
cropFactor
))]
avgClRGB
=
cv2
.
mean
(
frame
[
dCrop
[
0
]:
dCrop
[
1
],
dCrop
[
2
]:
dCrop
[
3
]])
avgClHue
=
rgbToHue
(
avgClRGB
)
avgClRGB
=
cv2
.
mean
(
frame
[
dCrop
[
0
]:
dCrop
[
1
],
dCrop
[
2
]:
dCrop
[
3
]])
avgClHue
=
rgbToHue
(
avgClRGB
)
if
scores
[
i
]
>
minDetectionScore
and
avgClHue
>
colorLow
and
avgClHue
<
colorHigh
:
cv2
.
rectangle
(
frame
,
(
int
(
x0
),
int
(
y0
)),
(
int
(
x1
),
int
(
y1
)),
(
0
,
255
,
0
),
2
)
if
scores
[
i
]
>
minDetectionScore
and
avgClHue
>
colorLow
and
avgClHue
<
colorHigh
:
cv2
.
rectangle
(
frame
,
(
int
(
x0
),
int
(
y0
)),
(
int
(
x1
),
int
(
y1
)),
(
0
,
255
,
0
),
2
)
if
labels
:
dist
=
distanceDetect
(
'
load-testImg
'
,
distWtsFile
,
[[
x0
,
x1
,
y0
,
y1
],
frame
.
shape
[:
2
]])
gbx
=
int
((
x1
+
x0
)
/
2
)
gby
=
int
((
y1
+
y0
)
/
2
)
cv2
.
putText
(
frame
,
'
x:{}, y:{}
'
.
format
(
gbx
,
gby
),
(
int
(
box
[
0
]),
int
(
box
[
1
])
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
1
,
(
255
,
0
,
0
),
3
)
dist
=
distanceDetect
(
'
load-testImg
'
,
distWtsFile
,
[[
x0
,
x1
,
y0
,
y1
],
frame
.
shape
[:
2
]])
gbx
=
int
((
x1
+
x0
)
/
2
)
gby
=
int
((
y1
+
y0
)
/
2
)
cv2
.
putText
(
frame
,
'
x:{}, y:{}
'
.
format
(
gbx
,
gby
),
(
int
(
box
[
0
]),
int
(
box
[
1
])
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
1
,
(
255
,
0
,
0
),
3
)
if
showSight
:
resized_frame
=
cv2
.
resize
(
frame
,(
400
,
300
))
cv2
.
imshow
(
'
Ball Detection
'
,
resized_frame
)
key
=
cv2
.
waitKey
(
1
)
&
0xFF
resized_frame
=
cv2
.
resize
(
frame
,(
400
,
300
))
cv2
.
imshow
(
'
Ball Detection
'
,
resized_frame
)
key
=
cv2
.
waitKey
(
1
)
&
0xFF
dist
=
int
(
dist
)
return
gbx
,
gby
,
dist
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment