Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
5d386070
Commit
5d386070
authored
Jul 19, 2016
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6895 from mshabunin:check-6851
parents
22919c39
95da5ec2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
5 deletions
+98
-5
calibinit.cpp
modules/calib3d/src/calibinit.cpp
+0
-0
checkchessboard.cpp
modules/calib3d/src/checkchessboard.cpp
+97
-0
test_chesscorners_timing.cpp
modules/calib3d/test/test_chesscorners_timing.cpp
+1
-5
No files found.
modules/calib3d/src/calibinit.cpp
View file @
5d386070
This diff is collapsed.
Click to expand it.
modules/calib3d/src/checkchessboard.cpp
View file @
5d386070
...
...
@@ -57,6 +57,8 @@
# endif
#endif
int
cvCheckChessboardBinary
(
IplImage
*
src
,
CvSize
size
);
static
void
icvGetQuadrangleHypotheses
(
CvSeq
*
contours
,
std
::
vector
<
std
::
pair
<
float
,
int
>
>&
quads
,
int
class_id
)
{
const
float
min_aspect_ratio
=
0.3
f
;
...
...
@@ -205,3 +207,97 @@ int cvCheckChessboard(IplImage* src, CvSize size)
return
result
;
}
// does a fast check if a chessboard is in the input image. This is a workaround to
// a problem of cvFindChessboardCorners being slow on images with no chessboard
// - src: input binary image
// - size: chessboard size
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
// 0 if there is no chessboard, -1 in case of error
int
cvCheckChessboardBinary
(
IplImage
*
src
,
CvSize
size
)
{
if
(
src
->
nChannels
>
1
)
{
cvError
(
CV_BadNumChannels
,
"cvCheckChessboard"
,
"supports single-channel images only"
,
__FILE__
,
__LINE__
);
}
if
(
src
->
depth
!=
8
)
{
cvError
(
CV_BadDepth
,
"cvCheckChessboard"
,
"supports depth=8 images only"
,
__FILE__
,
__LINE__
);
}
CvMemStorage
*
storage
=
cvCreateMemStorage
();
IplImage
*
white
=
cvCloneImage
(
src
);
IplImage
*
black
=
cvCloneImage
(
src
);
IplImage
*
thresh
=
cvCreateImage
(
cvGetSize
(
src
),
IPL_DEPTH_8U
,
1
);
int
result
=
0
;
for
(
int
erosion_count
=
0
;
erosion_count
<=
3
;
erosion_count
++
)
{
if
(
1
==
result
)
break
;
if
(
0
!=
erosion_count
)
// first iteration keeps original images
{
cvErode
(
white
,
white
,
NULL
,
1
);
cvDilate
(
black
,
black
,
NULL
,
1
);
}
cvThreshold
(
white
,
thresh
,
128
,
255
,
CV_THRESH_BINARY
);
CvSeq
*
first
=
0
;
std
::
vector
<
std
::
pair
<
float
,
int
>
>
quads
;
cvFindContours
(
thresh
,
storage
,
&
first
,
sizeof
(
CvContour
),
CV_RETR_CCOMP
);
icvGetQuadrangleHypotheses
(
first
,
quads
,
1
);
cvThreshold
(
black
,
thresh
,
128
,
255
,
CV_THRESH_BINARY_INV
);
cvFindContours
(
thresh
,
storage
,
&
first
,
sizeof
(
CvContour
),
CV_RETR_CCOMP
);
icvGetQuadrangleHypotheses
(
first
,
quads
,
0
);
const
size_t
min_quads_count
=
size
.
width
*
size
.
height
/
2
;
std
::
sort
(
quads
.
begin
(),
quads
.
end
(),
less_pred
);
// now check if there are many hypotheses with similar sizes
// do this by floodfill-style algorithm
const
float
size_rel_dev
=
0.4
f
;
for
(
size_t
i
=
0
;
i
<
quads
.
size
();
i
++
)
{
size_t
j
=
i
+
1
;
for
(;
j
<
quads
.
size
();
j
++
)
{
if
(
quads
[
j
].
first
/
quads
[
i
].
first
>
1.0
f
+
size_rel_dev
)
{
break
;
}
}
if
(
j
+
1
>
min_quads_count
+
i
)
{
// check the number of black and white squares
std
::
vector
<
int
>
counts
;
countClasses
(
quads
,
i
,
j
,
counts
);
const
int
black_count
=
cvRound
(
ceil
(
size
.
width
/
2.0
)
*
ceil
(
size
.
height
/
2.0
));
const
int
white_count
=
cvRound
(
floor
(
size
.
width
/
2.0
)
*
floor
(
size
.
height
/
2.0
));
if
(
counts
[
0
]
<
black_count
*
0.75
||
counts
[
1
]
<
white_count
*
0.75
)
{
continue
;
}
result
=
1
;
break
;
}
}
}
cvReleaseImage
(
&
thresh
);
cvReleaseImage
(
&
white
);
cvReleaseImage
(
&
black
);
cvReleaseMemStorage
(
&
storage
);
return
result
;
}
\ No newline at end of file
modules/calib3d/test/test_chesscorners_timing.cpp
View file @
5d386070
...
...
@@ -113,11 +113,7 @@ void CV_ChessboardDetectorTimingTest::run( int start_from )
if
(
img2
.
empty
()
)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"one of chessboard images can't be read: %s
\n
"
,
filename
.
c_str
()
);
if
(
max_idx
==
1
)
{
code
=
cvtest
::
TS
::
FAIL_MISSING_TEST_DATA
;
goto
_exit_
;
}
code
=
cvtest
::
TS
::
FAIL_MISSING_TEST_DATA
;
continue
;
}
...
...
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