Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
d07e70a4
Commit
d07e70a4
authored
Dec 14, 2016
by
Pavel Rojtberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aruco: use Mat().copyTo idiom instead of for loops
parent
a7ad78b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
65 deletions
+20
-65
aruco.cpp
modules/aruco/src/aruco.cpp
+11
-37
charuco.cpp
modules/aruco/src/charuco.cpp
+9
-28
No files found.
modules/aruco/src/aruco.cpp
View file @
d07e70a4
...
...
@@ -920,13 +920,8 @@ static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _
}
// create output
_objPoints
.
create
((
int
)
objPnts
.
size
(),
1
,
CV_32FC3
);
for
(
unsigned
int
i
=
0
;
i
<
objPnts
.
size
();
i
++
)
_objPoints
.
getMat
().
ptr
<
Point3f
>
(
0
)[
i
]
=
objPnts
[
i
];
_imgPoints
.
create
((
int
)
objPnts
.
size
(),
1
,
CV_32FC2
);
for
(
unsigned
int
i
=
0
;
i
<
imgPnts
.
size
();
i
++
)
_imgPoints
.
getMat
().
ptr
<
Point2f
>
(
0
)[
i
]
=
imgPnts
[
i
];
Mat
(
objPnts
).
copyTo
(
_objPoints
);
Mat
(
imgPnts
).
copyTo
(
_imgPoints
);
}
...
...
@@ -937,7 +932,7 @@ static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _
static
void
_projectUndetectedMarkers
(
const
Ptr
<
Board
>
&
_board
,
InputOutputArrayOfArrays
_detectedCorners
,
InputOutputArray
_detectedIds
,
InputArray
_cameraMatrix
,
InputArray
_distCoeffs
,
OutputArrayOfArrays
_undetectedMarkersProjectedCorners
,
vector
<
vector
<
Point2f
>
>&
_undetectedMarkersProjectedCorners
,
OutputArray
_undetectedMarkersIds
)
{
// first estimate board pose with the current avaible markers
...
...
@@ -972,18 +967,8 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray
// parse output
_undetectedMarkersIds
.
create
((
int
)
undetectedIds
.
size
(),
1
,
CV_32SC1
);
for
(
unsigned
int
i
=
0
;
i
<
undetectedIds
.
size
();
i
++
)
_undetectedMarkersIds
.
getMat
().
ptr
<
int
>
(
0
)[
i
]
=
undetectedIds
[
i
];
_undetectedMarkersProjectedCorners
.
create
((
int
)
undetectedCorners
.
size
(),
1
,
CV_32FC2
);
for
(
unsigned
int
i
=
0
;
i
<
undetectedCorners
.
size
();
i
++
)
{
_undetectedMarkersProjectedCorners
.
create
(
4
,
1
,
CV_32FC2
,
i
,
true
);
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
_undetectedMarkersProjectedCorners
.
getMat
(
i
).
ptr
<
Point2f
>
()[
j
]
=
undetectedCorners
[
i
][
j
];
}
}
Mat
(
undetectedIds
).
copyTo
(
_undetectedMarkersIds
);
_undetectedMarkersProjectedCorners
=
undetectedCorners
;
}
...
...
@@ -994,7 +979,7 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray
*/
static
void
_projectUndetectedMarkers
(
const
Ptr
<
Board
>
&
_board
,
InputOutputArrayOfArrays
_detectedCorners
,
InputOutputArray
_detectedIds
,
OutputArrayOfArrays
_undetectedMarkersProjectedCorners
,
vector
<
vector
<
Point2f
>
>&
_undetectedMarkersProjectedCorners
,
OutputArray
_undetectedMarkersIds
)
{
...
...
@@ -1042,20 +1027,14 @@ static void _projectUndetectedMarkers(const Ptr<Board> &_board, InputOutputArray
// get homography from detected markers
Mat
transformation
=
findHomography
(
detectedMarkersObj2DAll
,
imageCornersAll
);
_undetectedMarkersProjectedCorners
.
create
((
int
)
undetectedMarkersIds
.
size
(),
1
,
CV_32FC2
);
_undetectedMarkersProjectedCorners
.
resize
(
undetectedMarkersIds
.
size
()
);
// for each undetected marker, apply transformation
for
(
unsigned
int
i
=
0
;
i
<
undetectedMarkersObj2D
.
size
();
i
++
)
{
Mat
projectedMarker
;
perspectiveTransform
(
undetectedMarkersObj2D
[
i
],
projectedMarker
,
transformation
);
_undetectedMarkersProjectedCorners
.
create
(
4
,
1
,
CV_32FC2
,
i
,
true
);
projectedMarker
.
copyTo
(
_undetectedMarkersProjectedCorners
.
getMat
(
i
));
perspectiveTransform
(
undetectedMarkersObj2D
[
i
],
_undetectedMarkersProjectedCorners
[
i
],
transformation
);
}
_undetectedMarkersIds
.
create
((
int
)
undetectedMarkersIds
.
size
(),
1
,
CV_32SC1
);
for
(
unsigned
int
i
=
0
;
i
<
undetectedMarkersIds
.
size
();
i
++
)
_undetectedMarkersIds
.
getMat
().
ptr
<
int
>
(
0
)[
i
]
=
undetectedMarkersIds
[
i
];
Mat
(
undetectedMarkersIds
).
copyTo
(
_undetectedMarkersIds
);
}
...
...
@@ -1216,9 +1195,7 @@ void refineDetectedMarkers(InputArray _image, const Ptr<Board> &_board,
_detectedIds
.
clear
();
// parse output
_detectedIds
.
create
((
int
)
finalAcceptedIds
.
size
(),
1
,
CV_32SC1
);
for
(
unsigned
int
i
=
0
;
i
<
finalAcceptedIds
.
size
();
i
++
)
_detectedIds
.
getMat
().
ptr
<
int
>
(
0
)[
i
]
=
finalAcceptedIds
[
i
];
Mat
(
finalAcceptedIds
).
copyTo
(
_detectedIds
);
_detectedCorners
.
create
((
int
)
finalAcceptedCorners
.
size
(),
1
,
CV_32FC2
);
for
(
unsigned
int
i
=
0
;
i
<
finalAcceptedCorners
.
size
();
i
++
)
{
...
...
@@ -1248,10 +1225,7 @@ void refineDetectedMarkers(InputArray _image, const Ptr<Board> &_board,
}
if
(
_recoveredIdxs
.
needed
())
{
_recoveredIdxs
.
create
((
int
)
recoveredIdxs
.
size
(),
1
,
CV_32SC1
);
for
(
unsigned
int
i
=
0
;
i
<
recoveredIdxs
.
size
();
i
++
)
{
_recoveredIdxs
.
getMat
().
ptr
<
int
>
()[
i
]
=
recoveredIdxs
[
i
];
}
Mat
(
recoveredIdxs
).
copyTo
(
_recoveredIdxs
);
}
}
}
...
...
modules/aruco/src/charuco.cpp
View file @
d07e70a4
...
...
@@ -230,7 +230,7 @@ void CharucoBoard::_getNearestMarkerCorners() {
/**
* Remove charuco corners if any of their minMarkers closest markers has not been detected
*/
static
unsigned
int
_filterCornersWithoutMinMarkers
(
const
Ptr
<
CharucoBoard
>
&
_board
,
static
int
_filterCornersWithoutMinMarkers
(
const
Ptr
<
CharucoBoard
>
&
_board
,
InputArray
_allCharucoCorners
,
InputArray
_allCharucoIds
,
InputArray
_allArucoIds
,
int
minMarkers
,
...
...
@@ -265,17 +265,9 @@ static unsigned int _filterCornersWithoutMinMarkers(const Ptr<CharucoBoard> &_bo
}
// parse output
_filteredCharucoCorners
.
create
((
int
)
filteredCharucoCorners
.
size
(),
1
,
CV_32FC2
);
for
(
unsigned
int
i
=
0
;
i
<
filteredCharucoCorners
.
size
();
i
++
)
{
_filteredCharucoCorners
.
getMat
().
at
<
Point2f
>
(
i
)
=
filteredCharucoCorners
[
i
];
}
_filteredCharucoIds
.
create
((
int
)
filteredCharucoIds
.
size
(),
1
,
CV_32SC1
);
for
(
unsigned
int
i
=
0
;
i
<
filteredCharucoIds
.
size
();
i
++
)
{
_filteredCharucoIds
.
getMat
().
at
<
int
>
(
i
)
=
filteredCharucoIds
[
i
];
}
return
(
unsigned
int
)
filteredCharucoCorners
.
size
();
Mat
(
filteredCharucoCorners
).
copyTo
(
_filteredCharucoCorners
);
Mat
(
filteredCharucoIds
).
copyTo
(
_filteredCharucoIds
);
return
(
int
)
_filteredCharucoIds
.
total
();
}
...
...
@@ -326,7 +318,7 @@ class CharucoSubpixelParallel : public ParallelLoopBody {
* @brief From all projected chessboard corners, select those inside the image and apply subpixel
* refinement. Returns number of valid corners.
*/
static
unsigned
int
_selectAndRefineChessboardCorners
(
InputArray
_allCorners
,
InputArray
_image
,
static
int
_selectAndRefineChessboardCorners
(
InputArray
_allCorners
,
InputArray
_image
,
OutputArray
_selectedCorners
,
OutputArray
_selectedIds
,
const
vector
<
Size
>
&
winSizes
)
{
...
...
@@ -380,17 +372,9 @@ static unsigned int _selectAndRefineChessboardCorners(InputArray _allCorners, In
CharucoSubpixelParallel
(
&
grey
,
&
filteredChessboardImgPoints
,
&
filteredWinSizes
,
params
));
// parse output
_selectedCorners
.
create
((
int
)
filteredChessboardImgPoints
.
size
(),
1
,
CV_32FC2
);
for
(
unsigned
int
i
=
0
;
i
<
filteredChessboardImgPoints
.
size
();
i
++
)
{
_selectedCorners
.
getMat
().
at
<
Point2f
>
(
i
)
=
filteredChessboardImgPoints
[
i
];
}
_selectedIds
.
create
((
int
)
filteredIds
.
size
(),
1
,
CV_32SC1
);
for
(
unsigned
int
i
=
0
;
i
<
filteredIds
.
size
();
i
++
)
{
_selectedIds
.
getMat
().
at
<
int
>
(
i
)
=
filteredIds
[
i
];
}
return
(
unsigned
int
)
filteredChessboardImgPoints
.
size
();
Mat
(
filteredChessboardImgPoints
).
copyTo
(
_selectedCorners
);
Mat
(
filteredIds
).
copyTo
(
_selectedIds
);
return
(
int
)
filteredChessboardImgPoints
.
size
();
}
...
...
@@ -863,11 +847,8 @@ void detectCharucoDiamond(InputArray _image, InputArrayOfArrays _markerCorners,
if
(
diamondIds
.
size
()
>
0
)
{
// parse output
_diamondIds
.
create
((
int
)
diamondIds
.
size
(),
1
,
CV_32SC4
);
for
(
unsigned
int
i
=
0
;
i
<
diamondIds
.
size
();
i
++
)
_diamondIds
.
getMat
().
at
<
Vec4i
>
(
i
)
=
diamondIds
[
i
];
Mat
(
diamondIds
).
copyTo
(
_diamondIds
);
_diamondCorners
.
create
((
int
)
diamondCorners
.
size
(),
1
,
CV_32FC2
);
for
(
unsigned
int
i
=
0
;
i
<
diamondCorners
.
size
();
i
++
)
{
...
...
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