Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
November 2021 Blimp Competition
Manage
Activity
Members
Labels
Plan
Issues
2
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
Shahrul Kamil bin Hassan
November 2021 Blimp Competition
Commits
31bf942c
Commit
31bf942c
authored
3 years ago
by
Zhiying Li
Browse files
Options
Downloads
Patches
Plain Diff
Add AT detection to ESP32 Cam
parent
35402b9e
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread_AT.py
+73
-0
73 additions, 0 deletions
Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread_AT.py
with
73 additions
and
0 deletions
Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread_AT.py
0 → 100644
+
73
−
0
View file @
31bf942c
import
cv2
from
urllib.request
import
urlopen
,
Request
import
numpy
as
np
import
time
import
apriltag
def
nothing
(
x
):
pass
detector
=
apriltag
.
Detector
()
if
__name__
==
"
__main__
"
:
#change the IP address below according to the
#IP shown in the Serial monitor of Arduino code
# url='http://192.168.4.1/cam-hi.jpg'
# url='http://192.168.1.107/cam-hi.jpg'
url
=
'
http://192.168.4.1/cam-mid.jpg
'
# cv2.namedWindow("live transmission", cv2.WINDOW_AUTOSIZE)
cv2
.
namedWindow
(
"
live transmission
"
,
cv2
.
WINDOW_NORMAL
)
while
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
)
imgnp
=
np
.
array
(
bytearray
(
img_resp
.
read
()),
dtype
=
np
.
uint8
)
frame
=
cv2
.
imdecode
(
imgnp
,
-
1
)
gray_image
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
#print(len(gray_image.shape))
h
,
w
,
_
=
frame
.
shape
results
=
detector
.
detect
(
gray_image
)
# loop over the AprilTag detection results
for
r
in
results
:
# 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
)
print
(
"
[INFO] tag family: {}
"
.
format
(
tagFamily
))
# show the output image after AprilTag detection
cv2
.
imshow
(
"
Image
"
,
frame
)
key
=
cv2
.
waitKey
(
5
)
if
key
==
ord
(
'
q
'
):
break
#cv2.destroyAllWindows()
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