Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
kongfanhe
opencv_tutorial
Repository navigation
Code
Issues
Pull requests
1
(1)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
opencv_tutorial
/
test07_match.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
24 lines (17 loc) · 748 Bytes
main
Breadcrumbs
opencv_tutorial
/
test07_match.py
Copy path
Top
File metadata and controls
Code
Blame
24 lines (17 loc) · 748 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
# 图片的模板匹配(以匹配扑克牌上的菱形为例)
import
cv2
import
numpy
as
np
image
=
cv2
.
imread
(
"poker.jpg"
)
gray
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2GRAY
)
# 选取匹配模板
template
=
gray
[
75
:
105
,
235
:
265
]
# 使用标准相关匹配算法——将待检测对象和模板都标准化再来计算匹配度
match
=
cv2
.
matchTemplate
(
gray
,
template
,
cv2
.
TM_CCOEFF_NORMED
)
locations
=
np
.
where
(
match
>=
0.9
)
# 找出匹配系数大于0.9的匹配点
w
,
h
=
template
.
shape
[
0
:
2
]
for
p
in
zip
(
*
locations
[::
-
1
]):
# 循环遍历每一个匹配点并画出矩形框标记
x1
,
y1
=
p
[
0
],
p
[
1
]
x2
,
y2
=
x1
+
w
,
y1
+
h
cv2
.
rectangle
(
image
, (
x1
,
y1
), (
x2
,
y2
), (
0
,
255
,
0
),
2
)
cv2
.
imshow
(
"image"
,
image
)
cv2
.
waitKey
()
You can’t perform that action at this time.