FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
opencv_tutorials/python/code_054/opencv_054.py at master · HZHCoder1990/opencv_tutorials · GitHub
HZHCoder1990
/
opencv_tutorials
Public
forked from
JimmyHHua/opencv_tutorials
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
opencv_tutorials
/
python
/
code_054
/
opencv_054.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (27 loc) · 943 Bytes
Breadcrumbs
opencv_tutorials
/
python
/
code_054
/
opencv_054.py
Copy path
File metadata and controls
36 lines (27 loc) · 943 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
cv2
as
cv
import
numpy
as
np
def
canny_demo
(
image
):
t
=
80
canny_output
=
cv
.
Canny
(
image
,
t
,
t
*
2
)
cv
.
imshow
(
"canny_output"
,
canny_output
)
cv
.
imwrite
(
"canny_output.png"
,
canny_output
)
return
canny_output
src
=
cv
.
imread
(
"stuff.jpg"
)
cv
.
namedWindow
(
"input"
,
cv
.
WINDOW_AUTOSIZE
)
cv
.
imshow
(
"input"
,
src
)
binary
=
canny_demo
(
src
)
k
=
np
.
ones
((
3
,
3
),
dtype
=
np
.
uint8
)
binary
=
cv
.
morphologyEx
(
binary
,
cv
.
MORPH_DILATE
,
k
)
# 轮廓发现
out
,
contours
,
hierarchy
=
cv
.
findContours
(
binary
,
cv
.
RETR_EXTERNAL
,
cv
.
CHAIN_APPROX_SIMPLE
)
for
c
in
range
(
len
(
contours
)):
# 椭圆拟合
(
cx
,
cy
), (
a
,
b
),
angle
=
cv
.
fitEllipse
(
contours
[
c
])
# 绘制椭圆
cv
.
ellipse
(
src
, (
np
.
int32
(
cx
),
np
.
int32
(
cy
)),
(
np
.
int32
(
a
/
2
),
np
.
int32
(
b
/
2
)),
angle
,
0
,
360
, (
0
,
0
,
255
),
2
,
8
,
0
)
# 显示
cv
.
imshow
(
"contours_analysis"
,
src
)
cv
.
imwrite
(
"contours_analysis.png"
,
src
)
cv
.
waitKey
(
0
)
cv
.
destroyAllWindows
()
Back
|
FazBrowse Home
|
New Git URL