Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
11CTag
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
付尧(20研)
11CTag
Commits
e6acb730
Commit
e6acb730
authored
Oct 07, 2021
by
付尧(20研)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
main
parents
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
main.cpp
main.cpp
+71
-0
No files found.
main.cpp
0 → 100644
View file @
e6acb730
#include<opencv2\opencv.hpp>
using
namespace
cv
;
using
namespace
std
;
double
distance
(
Point2d
a
,
Point2d
b
)
{
return
sqrtf
((
powf
((
a
.
x
-
b
.
x
),
2
))
+
powf
((
a
.
y
-
b
.
y
),
2
));
}
int
main
()
{
string
imgpath
=
"D:/11CTag/t1.png"
;
Mat
img
=
imread
(
imgpath
,
0
);
Mat
local
;
adaptiveThreshold
(
img
,
local
,
255
,
cv
::
ADAPTIVE_THRESH_MEAN_C
,
cv
::
THRESH_BINARY
,
51
,
11
);
vector
<
vector
<
Point
>>
contours
;
vector
<
Vec4i
>
hierarchy
;
findContours
(
local
,
contours
,
hierarchy
,
RETR_TREE
,
CHAIN_APPROX_SIMPLE
,
Point
());
Mat
imageContours
=
Mat
::
zeros
(
local
.
size
(),
CV_8UC1
);
Mat
Contours
=
Mat
::
zeros
(
local
.
size
(),
CV_8UC1
);
//绘制
Mat
dstImg
=
Mat
::
zeros
(
local
.
size
(),
CV_8UC1
);
//绘制
vector
<
vector
<
Point
>>
contours_poly
(
contours
.
size
());
//用于存放折线点集
vector
<
vector
<
Point
>>
potential_quad
;
for
(
int
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
//contours[i]代表的是第i个轮廓,contours[i].size()代表的是第i个轮廓上所有的像素点数
//for (int j = 0; j < contours[i].size(); j++)
//{
//绘制出contours向量内所有的像素点
//Point P = Point(contours[i][j].x, contours[i][j].y);
//Contours.at<uchar>(P) = 255;
//}
approxPolyDP
(
Mat
(
contours
[
i
]),
contours_poly
[
i
],
arcLength
(
Mat
(
contours
[
i
]),
true
)
*
0.02
,
true
);
//矩形必须是四个点,必须是凸的,
if
(
contours_poly
[
i
].
size
()
==
4
&&
fabs
(
contourArea
(
Mat
(
contours_poly
[
i
])))
>
1000
&&
isContourConvex
(
Mat
(
contours_poly
[
i
])))
{
cout
<<
contours_poly
[
i
]
<<
endl
;
//potential_quad.push_back(contours_poly[i]);
drawContours
(
dstImg
,
contours_poly
,
i
,
Scalar
(
255
),
1
,
8
);
//绘制
Mat
imgtmp
=
img
.
clone
();
int
maxx
=
0
,
maxy
=
0
,
minx
=
9999
,
miny
=
9999
;
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
maxx
=
max
(
contours_poly
[
i
][
j
].
x
,
maxx
);
maxy
=
max
(
contours_poly
[
i
][
j
].
y
,
maxy
);
minx
=
min
(
contours_poly
[
i
][
j
].
x
,
minx
);
miny
=
min
(
contours_poly
[
i
][
j
].
y
,
miny
);
}
Rect
rect
(
minx
,
miny
,
maxx
-
minx
,
maxy
-
miny
);
Mat
roi
=
Mat
(
imgtmp
,
rect
);
SimpleBlobDetector
::
Params
params
;
params
.
blobColor
=
255
;
cv
::
Ptr
<
cv
::
SimpleBlobDetector
>
detector
=
SimpleBlobDetector
::
create
(
params
);
vector
<
KeyPoint
>
keyp
;
detector
->
detect
(
roi
,
keyp
);
cout
<<
keyp
.
size
()
<<
endl
;
imshow
(
"ROI"
,
roi
);
waitKey
(
0
);
}
drawContours
(
imageContours
,
contours
,
i
,
Scalar
(
255
),
1
,
8
,
hierarchy
);
}
imshow
(
"approx"
,
dstImg
);
imshow
(
"Contours Image"
,
imageContours
);
//轮廓
//imshow("Point of Contours", Contours); //向量contours内保存的所有轮廓点集
imshow
(
"imgraw"
,
local
);
waitKey
(
0
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment