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
745d8194
Commit
745d8194
authored
Nov 23, 2015
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #445 from paroj:use_cliparser
parents
0b5f2574
6b90a405
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
446 additions
and
674 deletions
+446
-674
calibrate_camera.cpp
modules/aruco/samples/calibrate_camera.cpp
+56
-74
calibrate_camera_charuco.cpp
modules/aruco/samples/calibrate_camera_charuco.cpp
+58
-76
create_board.cpp
modules/aruco/samples/create_board.cpp
+38
-67
create_board_charuco.cpp
modules/aruco/samples/create_board_charuco.cpp
+37
-65
create_diamond.cpp
modules/aruco/samples/create_diamond.cpp
+34
-62
create_marker.cpp
modules/aruco/samples/create_marker.cpp
+28
-58
detect_board.cpp
modules/aruco/samples/detect_board.cpp
+47
-66
detect_board_charuco.cpp
modules/aruco/samples/detect_board_charuco.cpp
+48
-66
detect_diamonds.cpp
modules/aruco/samples/detect_diamonds.cpp
+53
-73
detect_markers.cpp
modules/aruco/samples/detect_markers.cpp
+47
-67
No files found.
modules/aruco/samples/calibrate_camera.cpp
View file @
745d8194
...
...
@@ -49,59 +49,31 @@ using namespace std;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Calibration using a ArUco Planar Grid board"
<<
endl
;
cout
<<
"How to Use:"
<<
endl
;
cout
<<
"To capture a frame for calibration, press 'c',"
<<
endl
;
cout
<<
"If input comes from video, press any key for next frame"
<<
endl
;
cout
<<
"To finish capturing, press 'ESC' key and calibration starts."
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-w <nmarkers> # Number of markers in X direction"
<<
endl
;
cout
<<
"-h <nmarkers> # Number of markers in Y direction"
<<
endl
;
cout
<<
"-l <markerLength> # Marker side lenght (in meters)"
<<
endl
;
cout
<<
"-s <markerSeparation> # Separation between two consecutive"
<<
"markers in the grid (in meters)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"-o <outputFile> # Output file with calibrated camera parameters"
<<
endl
;
cout
<<
"[-v <videoFile>] # Input from video file, if ommited, input comes from camera"
<<
endl
;
cout
<<
"[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0"
<<
endl
;
cout
<<
"[-dp <detectorParams>] # File of marker detector parameters"
<<
endl
;
cout
<<
"[-rs] # Apply refind strategy"
<<
endl
;
cout
<<
"[-zt] # Assume zero tangential distortion"
<<
endl
;
cout
<<
"[-a <aspectRatio>] # Fix aspect ratio (fx/fy)"
<<
endl
;
cout
<<
"[-p] # Fix the principal point at the center"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
namespace
{
const
char
*
about
=
"Calibration using a ArUco Planar Grid board
\n
"
" To capture a frame for calibration, press 'c',
\n
"
" If input comes from video, press any key for next frame
\n
"
" To finish capturing, press 'ESC' key and calibration starts.
\n
"
;
const
char
*
keys
=
"{w | | Number of squares in X direction }"
"{h | | Number of squares in Y direction }"
"{l | | Marker side lenght (in meters) }"
"{s | | Separation between two consecutive markers in the grid (in meters) }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{@outfile |<none> | Output file with calibrated camera parameters }"
"{v | | Input from video file, if ommited, input comes from camera }"
"{ci | 0 | Camera id if input doesnt come from video (-v) }"
"{dp | | File of marker detector parameters }"
"{rs | false | Apply refind strategy }"
"{zt | false | Assume zero tangential distortion }"
"{a | | Fix aspect ratio (fx/fy) to this value }"
"{pc | false | Fix the principal point at the center }"
;
}
/**
*/
static
bool
readDetectorParameters
(
string
filename
,
aruco
::
DetectorParameters
&
params
)
{
...
...
@@ -177,55 +149,65 @@ static bool saveCameraParams(const string &filename, Size imageSize, float aspec
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-w"
,
argc
,
argv
)
||
!
isParam
(
"-h"
,
argc
,
argv
)
||
!
isParam
(
"-l"
,
argc
,
argv
)
||
!
isParam
(
"-s"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
)
||
!
isParam
(
"-o"
,
argc
,
argv
))
{
help
();
if
(
argc
<
6
)
{
parser
.
printMessage
();
return
0
;
}
int
markersX
=
atoi
(
getParam
(
"-w"
,
argc
,
argv
).
c_str
());
int
markersY
=
atoi
(
getParam
(
"-h"
,
argc
,
argv
).
c_str
());
float
markerLength
=
(
float
)
atof
(
getParam
(
"-l"
,
argc
,
argv
).
c_str
());
float
markerSeparation
=
(
float
)
atof
(
getParam
(
"-s"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
string
outputFile
=
getParam
(
"-o"
,
argc
,
argv
);
int
markersX
=
parser
.
get
<
int
>
(
"w"
);
int
markersY
=
parser
.
get
<
int
>
(
"w"
);
float
markerLength
=
parser
.
get
<
float
>
(
"l"
);
float
markerSeparation
=
parser
.
get
<
float
>
(
"s"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
string
outputFile
=
parser
.
get
<
String
>
(
0
);
int
calibrationFlags
=
0
;
float
aspectRatio
=
1
;
if
(
isParam
(
"-a"
,
argc
,
argv
))
{
if
(
parser
.
has
(
"a"
))
{
calibrationFlags
|=
CALIB_FIX_ASPECT_RATIO
;
aspectRatio
=
(
float
)
atof
(
getParam
(
"-a"
,
argc
,
argv
).
c_str
()
);
aspectRatio
=
parser
.
get
<
float
>
(
"a"
);
}
if
(
isParam
(
"-zt"
,
argc
,
argv
))
calibrationFlags
|=
CALIB_ZERO_TANGENT_DIST
;
if
(
isParam
(
"-p"
,
argc
,
argv
))
calibrationFlags
|=
CALIB_FIX_PRINCIPAL_POINT
;
if
(
parser
.
get
<
bool
>
(
"zt"
))
calibrationFlags
|=
CALIB_ZERO_TANGENT_DIST
;
if
(
parser
.
get
<
bool
>
(
"pc"
))
calibrationFlags
|=
CALIB_FIX_PRINCIPAL_POINT
;
aruco
::
DetectorParameters
detectorParams
;
if
(
isParam
(
"-dp"
,
argc
,
argv
))
{
bool
readOk
=
readDetectorParameters
(
getParam
(
"-dp"
,
argc
,
argv
),
detectorParams
);
if
(
parser
.
has
(
"dp"
))
{
bool
readOk
=
readDetectorParameters
(
parser
.
get
<
string
>
(
"dp"
),
detectorParams
);
if
(
!
readOk
)
{
cerr
<<
"Invalid detector parameters file"
<<
endl
;
return
0
;
}
}
bool
refindStrategy
=
false
;
if
(
isParam
(
"-rs"
,
argc
,
argv
))
refindStrategy
=
true
;
bool
refindStrategy
=
parser
.
get
<
bool
>
(
"rs"
);
int
camId
=
parser
.
get
<
int
>
(
"ci"
);
String
video
;
if
(
parser
.
has
(
"v"
))
{
video
=
parser
.
get
<
String
>
(
"v"
);
}
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
VideoCapture
inputVideo
;
int
waitTime
;
if
(
isParam
(
"-v"
,
argc
,
argv
))
{
inputVideo
.
open
(
getParam
(
"-v"
,
argc
,
argv
)
);
if
(
!
video
.
empty
(
))
{
inputVideo
.
open
(
video
);
waitTime
=
0
;
}
else
{
int
camId
=
0
;
if
(
isParam
(
"-ci"
,
argc
,
argv
))
camId
=
atoi
(
getParam
(
"-ci"
,
argc
,
argv
).
c_str
());
inputVideo
.
open
(
camId
);
waitTime
=
10
;
}
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
// create board object
aruco
::
GridBoard
board
=
aruco
::
GridBoard
::
create
(
markersX
,
markersY
,
markerLength
,
markerSeparation
,
dictionary
);
...
...
modules/aruco/samples/calibrate_camera_charuco.cpp
View file @
745d8194
...
...
@@ -48,60 +48,32 @@ the use of this software, even if advised of the possibility of such damage.
using
namespace
std
;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Calibration using a ChArUco board"
<<
endl
;
cout
<<
"How to Use:"
<<
endl
;
cout
<<
"To capture a frame for calibration, press 'c',"
<<
endl
;
cout
<<
"If input comes from video, press any key for next frame"
<<
endl
;
cout
<<
"To finish capturing, press 'ESC' key and calibration starts."
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-w <nmarkers> # Number of markers in X direction"
<<
endl
;
cout
<<
"-h <nsquares> # Number of squares in Y direction"
<<
endl
;
cout
<<
"-sl <squareLength> # Square side lenght (in meters)"
<<
endl
;
cout
<<
"-ml <markerLength> # Marker side lenght (in meters)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"-o <outputFile> # Output file with calibrated camera parameters"
<<
endl
;
cout
<<
"[-v <videoFile>] # Input from video file, if ommited, input comes from camera"
<<
endl
;
cout
<<
"[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0"
<<
endl
;
cout
<<
"[-dp <detectorParams>] # File of marker detector parameters"
<<
endl
;
cout
<<
"[-rs] # Apply refind strategy"
<<
endl
;
cout
<<
"[-zt] # Assume zero tangential distortion"
<<
endl
;
cout
<<
"[-a <aspectRatio>] # Fix aspect ratio (fx/fy)"
<<
endl
;
cout
<<
"[-p] # Fix the principal point at the center"
<<
endl
;
cout
<<
"[-sc] # Show detected chessboard corners after calibration"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
namespace
{
const
char
*
about
=
"Calibration using a ChArUco board
\n
"
" To capture a frame for calibration, press 'c',
\n
"
" If input comes from video, press any key for next frame
\n
"
" To finish capturing, press 'ESC' key and calibration starts.
\n
"
;
const
char
*
keys
=
"{w | | Number of squares in X direction }"
"{h | | Number of squares in Y direction }"
"{sl | | Square side lenght (in pixels) }"
"{ml | | Marker side lenght (in pixels) }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{@outfile |<none> | Output file with calibrated camera parameters }"
"{v | | Input from video file, if ommited, input comes from camera }"
"{ci | 0 | Camera id if input doesnt come from video (-v) }"
"{dp | | File of marker detector parameters }"
"{rs | false | Apply refind strategy }"
"{zt | false | Assume zero tangential distortion }"
"{a | | Fix aspect ratio (fx/fy) to this value }"
"{pc | false | Fix the principal point at the center }"
"{sc | false | Show detected chessboard corners after calibration }"
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
}
/**
*/
static
bool
readDetectorParameters
(
string
filename
,
aruco
::
DetectorParameters
&
params
)
{
...
...
@@ -177,57 +149,67 @@ static bool saveCameraParams(const string &filename, Size imageSize, float aspec
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-w"
,
argc
,
argv
)
||
!
isParam
(
"-h"
,
argc
,
argv
)
||
!
isParam
(
"-sl"
,
argc
,
argv
)
||
!
isParam
(
"-ml"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
)
||
!
isParam
(
"-o"
,
argc
,
argv
))
{
help
();
if
(
argc
<
7
)
{
parser
.
printMessage
();
return
0
;
}
int
squaresX
=
atoi
(
getParam
(
"-w"
,
argc
,
argv
).
c_str
());
int
squaresY
=
atoi
(
getParam
(
"-h"
,
argc
,
argv
).
c_str
());
float
squareLength
=
(
float
)
atof
(
getParam
(
"-sl"
,
argc
,
argv
).
c_str
());
float
markerLength
=
(
float
)
atof
(
getParam
(
"-ml"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
string
outputFile
=
getParam
(
"-o"
,
argc
,
argv
);
int
squaresX
=
parser
.
get
<
int
>
(
"w"
);
int
squaresY
=
parser
.
get
<
int
>
(
"h"
);
float
squareLength
=
parser
.
get
<
float
>
(
"sl"
);
float
markerLength
=
parser
.
get
<
float
>
(
"ml"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
string
outputFile
=
parser
.
get
<
string
>
(
0
);
bool
showChessboardCorners
=
isParam
(
"-sc"
,
argc
,
argv
);
bool
showChessboardCorners
=
parser
.
get
<
bool
>
(
"sc"
);
int
calibrationFlags
=
0
;
float
aspectRatio
=
1
;
if
(
isParam
(
"-a"
,
argc
,
argv
))
{
if
(
parser
.
has
(
"a"
))
{
calibrationFlags
|=
CALIB_FIX_ASPECT_RATIO
;
aspectRatio
=
(
float
)
atof
(
getParam
(
"-a"
,
argc
,
argv
).
c_str
()
);
aspectRatio
=
parser
.
get
<
float
>
(
"a"
);
}
if
(
isParam
(
"-zt"
,
argc
,
argv
))
calibrationFlags
|=
CALIB_ZERO_TANGENT_DIST
;
if
(
isParam
(
"-p"
,
argc
,
argv
))
calibrationFlags
|=
CALIB_FIX_PRINCIPAL_POINT
;
if
(
parser
.
get
<
bool
>
(
"zt"
))
calibrationFlags
|=
CALIB_ZERO_TANGENT_DIST
;
if
(
parser
.
get
<
bool
>
(
"pc"
))
calibrationFlags
|=
CALIB_FIX_PRINCIPAL_POINT
;
aruco
::
DetectorParameters
detectorParams
;
if
(
isParam
(
"-dp"
,
argc
,
argv
))
{
bool
readOk
=
readDetectorParameters
(
getParam
(
"-dp"
,
argc
,
argv
),
detectorParams
);
if
(
parser
.
has
(
"dp"
))
{
bool
readOk
=
readDetectorParameters
(
parser
.
get
<
string
>
(
"dp"
),
detectorParams
);
if
(
!
readOk
)
{
cerr
<<
"Invalid detector parameters file"
<<
endl
;
return
0
;
}
}
bool
refindStrategy
=
false
;
if
(
isParam
(
"-rs"
,
argc
,
argv
))
refindStrategy
=
true
;
bool
refindStrategy
=
parser
.
get
<
bool
>
(
"rs"
);
int
camId
=
parser
.
get
<
int
>
(
"ci"
);
String
video
;
if
(
parser
.
has
(
"v"
))
{
video
=
parser
.
get
<
String
>
(
"v"
);
}
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
VideoCapture
inputVideo
;
int
waitTime
;
if
(
isParam
(
"-v"
,
argc
,
argv
))
{
inputVideo
.
open
(
getParam
(
"-v"
,
argc
,
argv
)
);
if
(
!
video
.
empty
(
))
{
inputVideo
.
open
(
video
);
waitTime
=
0
;
}
else
{
int
camId
=
0
;
if
(
isParam
(
"-ci"
,
argc
,
argv
))
camId
=
atoi
(
getParam
(
"-ci"
,
argc
,
argv
).
c_str
());
inputVideo
.
open
(
camId
);
waitTime
=
10
;
}
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
// create charuco board object
aruco
::
CharucoBoard
board
=
aruco
::
CharucoBoard
::
create
(
squaresX
,
squaresY
,
squareLength
,
markerLength
,
dictionary
);
...
...
modules/aruco/samples/create_board.cpp
View file @
745d8194
...
...
@@ -39,92 +39,63 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp>
#include <iostream>
using
namespace
std
;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Create an ArUco grid board image"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-o <image> # Output image"
<<
endl
;
cout
<<
"-w <nmarkers> # Number of markers in X direction"
<<
endl
;
cout
<<
"-h <nmarkers> # Number of markers in Y direction"
<<
endl
;
cout
<<
"-l <markerLength> # Marker side lenght (in pixels)"
<<
endl
;
cout
<<
"-s <markerSeparation> # Separation between two consecutive"
<<
"markers in the grid (in pixels)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"[-m <marginSize>] # Margins size (in pixels)"
<<
"Default is marker separation"
<<
endl
;
cout
<<
"[-bb <int>] # Number of bits in marker borders. Default is 1"
<<
endl
;
cout
<<
"[-si] # show generated image"
<<
endl
;
namespace
{
const
char
*
about
=
"Create an ArUco grid board image"
;
const
char
*
keys
=
"{@outfile |<none> | Output image }"
"{w | | Number of markers in X direction }"
"{h | | Number of markers in Y direction }"
"{l | | Marker side lenght (in pixels) }"
"{s | | Separation between two consecutive markers in the grid (in pixels)}"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{m | | Margins size (in pixels). Default is marker separation (-s) }"
"{bb | 1 | Number of bits in marker borders }"
"{si | false | show generated image }"
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
}
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-w"
,
argc
,
argv
)
||
!
isParam
(
"-h"
,
argc
,
argv
)
||
!
isParam
(
"-l"
,
argc
,
argv
)
||
!
isParam
(
"-s"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
)
||
!
isParam
(
"-o"
,
argc
,
argv
))
{
help
();
if
(
argc
<
7
)
{
parser
.
printMessage
();
return
0
;
}
int
markersX
=
atoi
(
getParam
(
"-w"
,
argc
,
argv
).
c_str
());
int
markersY
=
atoi
(
getParam
(
"-h"
,
argc
,
argv
).
c_str
());
int
markerLength
=
atoi
(
getParam
(
"-l"
,
argc
,
argv
).
c_str
());
int
markerSeparation
=
atoi
(
getParam
(
"-s"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
int
markersX
=
parser
.
get
<
int
>
(
"w"
);
int
markersY
=
parser
.
get
<
int
>
(
"h"
);
int
markerLength
=
parser
.
get
<
int
>
(
"l"
);
int
markerSeparation
=
parser
.
get
<
int
>
(
"s"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
int
margins
=
markerSeparation
;
if
(
isParam
(
"-m"
,
argc
,
argv
))
{
margins
=
atoi
(
getParam
(
"-m"
,
argc
,
argv
).
c_str
()
);
if
(
parser
.
has
(
"m"
))
{
margins
=
parser
.
get
<
int
>
(
"m"
);
}
int
borderBits
=
1
;
if
(
isParam
(
"-bb"
,
argc
,
argv
))
{
borderBits
=
atoi
(
getParam
(
"-bb"
,
argc
,
argv
).
c_str
());
}
int
borderBits
=
parser
.
get
<
int
>
(
"bb"
);
bool
showImage
=
parser
.
get
<
bool
>
(
"si"
);
bool
showImage
=
false
;
if
(
isParam
(
"-si"
,
argc
,
argv
))
showImage
=
true
;
String
out
=
parser
.
get
<
String
>
(
0
);
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
Size
imageSize
;
imageSize
.
width
=
markersX
*
(
markerLength
+
markerSeparation
)
-
markerSeparation
+
2
*
margins
;
imageSize
.
height
=
markersY
*
(
markerLength
+
markerSeparation
)
-
markerSeparation
+
2
*
margins
;
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
aruco
::
GridBoard
board
=
aruco
::
GridBoard
::
create
(
markersX
,
markersY
,
float
(
markerLength
),
float
(
markerSeparation
),
dictionary
);
...
...
@@ -137,7 +108,7 @@ int main(int argc, char *argv[]) {
waitKey
(
0
);
}
imwrite
(
getParam
(
"-o"
,
argc
,
argv
)
,
boardImage
);
imwrite
(
out
,
boardImage
);
return
0
;
}
modules/aruco/samples/create_board_charuco.cpp
View file @
745d8194
...
...
@@ -39,85 +39,57 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp>
#include <opencv2/aruco/charuco.hpp>
#include <iostream>
using
namespace
std
;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Create a ChArUco board image"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-o <image> # Output image"
<<
endl
;
cout
<<
"-w <nsquares> # Number of squares in X direction"
<<
endl
;
cout
<<
"-h <nsquares> # Number of squares in Y direction"
<<
endl
;
cout
<<
"-sl <squareLength> # Square side lenght (in pixels)"
<<
endl
;
cout
<<
"-ml <markerLength> # Marker side lenght (in pixels)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"[-m <marginSize>] # Margins size (in pixels)"
<<
"Default is (squareLength-markerLength)"
<<
endl
;
cout
<<
"[-bb <int>] # Number of bits in marker borders. Default is 1"
<<
endl
;
cout
<<
"[-si] # show generated image"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
namespace
{
const
char
*
about
=
"Create a ChArUco board image"
;
const
char
*
keys
=
"{@outfile |<none> | Output image }"
"{w | | Number of squares in X direction }"
"{h | | Number of squares in Y direction }"
"{sl | | Square side lenght (in pixels) }"
"{ml | | Marker side lenght (in pixels) }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{m | | Margins size (in pixels). Default is (squareLength-markerLength) }"
"{bb | 1 | Number of bits in marker borders }"
"{si | false | show generated image }"
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
}
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-w"
,
argc
,
argv
)
||
!
isParam
(
"-h"
,
argc
,
argv
)
||
!
isParam
(
"-sl"
,
argc
,
argv
)
||
!
isParam
(
"-ml"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
)
||
!
isParam
(
"-o"
,
argc
,
argv
))
{
help
();
if
(
argc
<
7
)
{
parser
.
printMessage
();
return
0
;
}
int
squaresX
=
atoi
(
getParam
(
"-w"
,
argc
,
argv
).
c_str
());
int
squaresY
=
atoi
(
getParam
(
"-h"
,
argc
,
argv
).
c_str
());
int
squareLength
=
atoi
(
getParam
(
"-sl"
,
argc
,
argv
).
c_str
());
int
markerLength
=
atoi
(
getParam
(
"-ml"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
int
squaresX
=
parser
.
get
<
int
>
(
"w"
);
int
squaresY
=
parser
.
get
<
int
>
(
"h"
);
int
squareLength
=
parser
.
get
<
int
>
(
"sl"
);
int
markerLength
=
parser
.
get
<
int
>
(
"ml"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
int
margins
=
squareLength
-
markerLength
;
if
(
isParam
(
"-m"
,
argc
,
argv
))
{
margins
=
atoi
(
getParam
(
"-m"
,
argc
,
argv
).
c_str
()
);
if
(
parser
.
has
(
"m"
))
{
margins
=
parser
.
get
<
int
>
(
"m"
);
}
int
borderBits
=
1
;
if
(
isParam
(
"-bb"
,
argc
,
argv
))
{
borderBits
=
atoi
(
getParam
(
"-bb"
,
argc
,
argv
).
c_str
());
int
borderBits
=
parser
.
get
<
int
>
(
"bb"
);
bool
showImage
=
parser
.
get
<
bool
>
(
"si"
);
String
out
=
parser
.
get
<
String
>
(
0
);
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
bool
showImage
=
false
;
if
(
isParam
(
"-si"
,
argc
,
argv
))
showImage
=
true
;
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
))
;
Size
imageSize
;
imageSize
.
width
=
squaresX
*
squareLength
+
2
*
margins
;
...
...
@@ -135,7 +107,7 @@ int main(int argc, char *argv[]) {
waitKey
(
0
);
}
imwrite
(
getParam
(
"-o"
,
argc
,
argv
)
,
boardImage
);
imwrite
(
out
,
boardImage
);
return
0
;
}
modules/aruco/samples/create_diamond.cpp
View file @
745d8194
...
...
@@ -45,65 +45,50 @@ the use of this software, even if advised of the possibility of such damage.
using
namespace
std
;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Create a ChArUco marker image"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-o <image> # Output image"
<<
endl
;
cout
<<
"-sl <squareLength> # Square side lenght (in pixels)"
<<
endl
;
cout
<<
"-ml <markerLength> # Marker side lenght (in pixels)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"-ids <id1,id2,id3,id4> # Four ids for the ChArUco marker"
<<
endl
;
cout
<<
"[-m <marginSize>] # Margins size (in pixels). Default is 0"
<<
endl
;
cout
<<
"[-bb <int>] # Number of bits in marker borders. Default is 1"
<<
endl
;
cout
<<
"[-si] # show generated image"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
namespace
{
const
char
*
about
=
"Create a ChArUco marker image"
;
const
char
*
keys
=
"{@outfile |<none> | Output image }"
"{sl | | Square side lenght (in pixels) }"
"{ml | | Marker side lenght (in pixels) }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{ids |<none> | Four ids for the ChArUco marker: id1,id2,id3,id4 }"
"{m | 0 | Margins size (in pixels) }"
"{bb | 1 | Number of bits in marker borders }"
"{si | false | show generated image }"
;
}
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
argc
<
4
)
{
parser
.
printMessage
();
return
0
;
}
if
(
!
isParam
(
"-sl"
,
argc
,
argv
)
||
!
isParam
(
"-ml"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
)
||
!
isParam
(
"-ids"
,
argc
,
argv
))
{
help
();
int
squareLength
=
parser
.
get
<
int
>
(
"sl"
);
int
markerLength
=
parser
.
get
<
int
>
(
"ml"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
string
idsString
=
parser
.
get
<
string
>
(
"ids"
);
int
margins
=
parser
.
get
<
int
>
(
"m"
);
int
borderBits
=
parser
.
get
<
int
>
(
"bb"
);
bool
showImage
=
parser
.
get
<
bool
>
(
"si"
);
String
out
=
parser
.
get
<
String
>
(
0
);
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
int
squareLength
=
atoi
(
getParam
(
"-sl"
,
argc
,
argv
).
c_str
());
int
markerLength
=
atoi
(
getParam
(
"-ml"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
string
idsString
=
getParam
(
"-ids"
,
argc
,
argv
);
istringstream
ss
(
idsString
);
vector
<
string
>
splittedIds
;
string
token
;
...
...
@@ -111,26 +96,13 @@ int main(int argc, char *argv[]) {
splittedIds
.
push_back
(
token
);
if
(
splittedIds
.
size
()
<
4
)
{
cerr
<<
"Incorrect ids format"
<<
endl
;
help
();
parser
.
printMessage
();
return
0
;
}
Vec4i
ids
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
ids
[
i
]
=
atoi
(
splittedIds
[
i
].
c_str
());
int
margins
=
0
;
if
(
isParam
(
"-m"
,
argc
,
argv
))
{
margins
=
atoi
(
getParam
(
"-m"
,
argc
,
argv
).
c_str
());
}
int
borderBits
=
1
;
if
(
isParam
(
"-bb"
,
argc
,
argv
))
{
borderBits
=
atoi
(
getParam
(
"-bb"
,
argc
,
argv
).
c_str
());
}
bool
showImage
=
false
;
if
(
isParam
(
"-si"
,
argc
,
argv
))
showImage
=
true
;
Mat
markerImg
;
aruco
::
drawCharucoDiamond
(
dictionary
,
ids
,
squareLength
,
markerLength
,
markerImg
,
margins
,
borderBits
);
...
...
@@ -140,7 +112,7 @@ int main(int argc, char *argv[]) {
waitKey
(
0
);
}
imwrite
(
getParam
(
"-o"
,
argc
,
argv
)
,
markerImg
);
imwrite
(
out
,
markerImg
);
return
0
;
}
modules/aruco/samples/create_marker.cpp
View file @
745d8194
...
...
@@ -39,78 +39,48 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp>
#include <iostream>
using
namespace
std
;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Create an ArUco marker image"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-o <image> # Output image"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"-id <int> # Marker id in the dictionary"
<<
endl
;
cout
<<
"[-ms <int>] # Marker size in pixels. Default is 200"
<<
endl
;
cout
<<
"[-bb <int>] # Number of bits in marker borders. Default is 1"
<<
endl
;
cout
<<
"[-si] # show generated image"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
namespace
{
const
char
*
about
=
"Create an ArUco marker image"
;
const
char
*
keys
=
"{@outfile |<none> | Output image }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{id | | Marker id in the dictionary }"
"{ms | 200 | Marker size in pixels }"
"{bb | 1 | Number of bits in marker borders }"
"{si | false | show generated image }"
;
}
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-d"
,
argc
,
argv
)
||
!
isParam
(
"-o"
,
argc
,
argv
)
)
{
help
();
if
(
argc
<
4
)
{
parser
.
printMessage
();
return
0
;
}
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
int
markerId
=
parser
.
get
<
int
>
(
"id"
);
int
borderBits
=
parser
.
get
<
int
>
(
"bb"
);
int
markerSize
=
parser
.
get
<
int
>
(
"ms"
);
bool
showImage
=
parser
.
get
<
bool
>
(
"si"
);
int
markerId
=
atoi
(
getParam
(
"-id"
,
argc
,
argv
).
c_str
());
int
borderBits
=
1
;
if
(
isParam
(
"-bb"
,
argc
,
argv
))
{
borderBits
=
atoi
(
getParam
(
"-bb"
,
argc
,
argv
).
c_str
());
}
String
out
=
parser
.
get
<
String
>
(
0
);
i
nt
markerSize
=
200
;
if
(
isParam
(
"-ms"
,
argc
,
argv
))
{
markerSize
=
atoi
(
getParam
(
"-ms"
,
argc
,
argv
).
c_str
())
;
i
f
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
bool
showImage
=
false
;
if
(
isParam
(
"-si"
,
argc
,
argv
))
showImage
=
true
;
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
))
;
Mat
markerImg
;
aruco
::
drawMarker
(
dictionary
,
markerId
,
markerSize
,
markerImg
,
borderBits
);
...
...
@@ -120,7 +90,7 @@ int main(int argc, char *argv[]) {
waitKey
(
0
);
}
imwrite
(
getParam
(
"-o"
,
argc
,
argv
)
,
markerImg
);
imwrite
(
out
,
markerImg
);
return
0
;
}
modules/aruco/samples/detect_board.cpp
View file @
745d8194
...
...
@@ -45,52 +45,25 @@ the use of this software, even if advised of the possibility of such damage.
using
namespace
std
;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Pose estimation using a ArUco Planar Grid board"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-w <nmarkers> # Number of markers in X direction"
<<
endl
;
cout
<<
"-h <nmarkers> # Number of markers in Y direction"
<<
endl
;
cout
<<
"-l <markerLength> # Marker side lenght (in meters)"
<<
endl
;
cout
<<
"-s <markerSeparation> # Separation between two consecutive"
<<
"markers in the grid (in meters)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"-c <cameraParams> # Camera intrinsic parameters file"
<<
endl
;
cout
<<
"[-v <videoFile>] # Input from video file, if ommited, input comes from camera"
<<
endl
;
cout
<<
"[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0"
<<
endl
;
cout
<<
"[-dp <detectorParams>] # File of marker detector parameters"
<<
endl
;
cout
<<
"[-rs] # Apply refind strategy"
<<
endl
;
cout
<<
"[-r] # show rejected candidates too"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
namespace
{
const
char
*
about
=
"Pose estimation using a ArUco Planar Grid board"
;
const
char
*
keys
=
"{w | | Number of squares in X direction }"
"{h | | Number of squares in Y direction }"
"{l | | Marker side lenght (in pixels) }"
"{s | | Separation between two consecutive markers in the grid (in pixels)}"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{c | | Output file with calibrated camera parameters }"
"{v | | Input from video file, if ommited, input comes from camera }"
"{ci | 0 | Camera id if input doesnt come from video (-v) }"
"{dp | | File of marker detector parameters }"
"{rs | | Apply refind strategy }"
"{r | | show rejected candidates too }"
;
}
/**
*/
static
bool
readCameraParameters
(
string
filename
,
Mat
&
camMatrix
,
Mat
&
distCoeffs
)
{
...
...
@@ -137,27 +110,27 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-w"
,
argc
,
argv
)
||
!
isParam
(
"-h"
,
argc
,
argv
)
||
!
isParam
(
"-l"
,
argc
,
argv
)
||
!
isParam
(
"-s"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
)
||
!
isParam
(
"-c"
,
argc
,
argv
))
{
help
();
if
(
argc
<
7
)
{
parser
.
printMessage
();
return
0
;
}
int
markersX
=
atoi
(
getParam
(
"-w"
,
argc
,
argv
).
c_str
());
int
markersY
=
atoi
(
getParam
(
"-h"
,
argc
,
argv
).
c_str
());
float
markerLength
=
(
float
)
atof
(
getParam
(
"-l"
,
argc
,
argv
).
c_str
());
float
markerSeparation
=
(
float
)
atof
(
getParam
(
"-s"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
int
markersX
=
parser
.
get
<
int
>
(
"w"
);
int
markersY
=
parser
.
get
<
int
>
(
"h"
);
float
markerLength
=
parser
.
get
<
float
>
(
"l"
);
float
markerSeparation
=
parser
.
get
<
float
>
(
"s"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
bool
showRejected
=
parser
.
has
(
"r"
);
bool
refindStrategy
=
parser
.
has
(
"rs"
);
int
camId
=
parser
.
get
<
int
>
(
"ci"
);
bool
showRejected
=
false
;
if
(
isParam
(
"-r"
,
argc
,
argv
))
showRejected
=
true
;
Mat
camMatrix
,
distCoeffs
;
if
(
isParam
(
"-c"
,
argc
,
argv
))
{
bool
readOk
=
readCameraParameters
(
getParam
(
"-c"
,
argc
,
argv
),
camMatrix
,
distCoeffs
);
if
(
parser
.
has
(
"c"
))
{
bool
readOk
=
readCameraParameters
(
parser
.
get
<
string
>
(
"c"
),
camMatrix
,
distCoeffs
);
if
(
!
readOk
)
{
cerr
<<
"Invalid camera file"
<<
endl
;
return
0
;
...
...
@@ -165,8 +138,8 @@ int main(int argc, char *argv[]) {
}
aruco
::
DetectorParameters
detectorParams
;
if
(
isParam
(
"-dp"
,
argc
,
argv
))
{
bool
readOk
=
readDetectorParameters
(
getParam
(
"-dp"
,
argc
,
argv
),
detectorParams
);
if
(
parser
.
has
(
"dp"
))
{
bool
readOk
=
readDetectorParameters
(
parser
.
get
<
string
>
(
"dp"
),
detectorParams
);
if
(
!
readOk
)
{
cerr
<<
"Invalid detector parameters file"
<<
endl
;
return
0
;
...
...
@@ -174,17 +147,25 @@ int main(int argc, char *argv[]) {
}
detectorParams
.
doCornerRefinement
=
true
;
// do corner refinement in markers
bool
refindStrategy
=
false
;
if
(
isParam
(
"-rs"
,
argc
,
argv
))
refindStrategy
=
true
;
String
video
;
if
(
parser
.
has
(
"v"
))
{
video
=
parser
.
get
<
String
>
(
"v"
);
}
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
VideoCapture
inputVideo
;
int
waitTime
;
if
(
isParam
(
"-v"
,
argc
,
argv
))
{
inputVideo
.
open
(
getParam
(
"-v"
,
argc
,
argv
)
);
if
(
!
video
.
empty
(
))
{
inputVideo
.
open
(
video
);
waitTime
=
0
;
}
else
{
int
camId
=
0
;
if
(
isParam
(
"-ci"
,
argc
,
argv
))
camId
=
atoi
(
getParam
(
"-ci"
,
argc
,
argv
).
c_str
());
inputVideo
.
open
(
camId
);
waitTime
=
10
;
}
...
...
modules/aruco/samples/detect_board_charuco.cpp
View file @
745d8194
...
...
@@ -46,50 +46,25 @@ using namespace std;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Pose estimation using a ChArUco board"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-w <nmarkers> # Number of markers in X direction"
<<
endl
;
cout
<<
"-h <nsquares> # Number of squares in Y direction"
<<
endl
;
cout
<<
"-sl <squareLength> # Square side lenght (in meters)"
<<
endl
;
cout
<<
"-ml <markerLength> # Marker side lenght (in meters)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"[-c <cameraParams>] # Camera intrinsic parameters file"
<<
endl
;
cout
<<
"[-v <videoFile>] # Input from video file, if ommited, input comes from camera"
<<
endl
;
cout
<<
"[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0"
<<
endl
;
cout
<<
"[-dp <detectorParams>] # File of marker detector parameters"
<<
endl
;
cout
<<
"[-rs] # Apply refind strategy"
<<
endl
;
cout
<<
"[-r] # show rejected candidates too"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
namespace
{
const
char
*
about
=
"Pose estimation using a ChArUco board"
;
const
char
*
keys
=
"{w | | Number of squares in X direction }"
"{h | | Number of squares in Y direction }"
"{sl | | Square side lenght (in pixels) }"
"{ml | | Marker side lenght (in pixels) }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{c | | Output file with calibrated camera parameters }"
"{v | | Input from video file, if ommited, input comes from camera }"
"{ci | 0 | Camera id if input doesnt come from video (-v) }"
"{dp | | File of marker detector parameters }"
"{rs | | Apply refind strategy }"
"{r | | show rejected candidates too }"
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
}
/**
*/
static
bool
readCameraParameters
(
string
filename
,
Mat
&
camMatrix
,
Mat
&
distCoeffs
)
{
...
...
@@ -135,27 +110,31 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-w"
,
argc
,
argv
)
||
!
isParam
(
"-h"
,
argc
,
argv
)
||
!
isParam
(
"-sl"
,
argc
,
argv
)
||
!
isParam
(
"-ml"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
))
{
help
();
if
(
argc
<
6
)
{
parser
.
printMessage
();
return
0
;
}
int
squaresX
=
atoi
(
getParam
(
"-w"
,
argc
,
argv
).
c_str
());
int
squaresY
=
atoi
(
getParam
(
"-h"
,
argc
,
argv
).
c_str
());
float
squareLength
=
(
float
)
atof
(
getParam
(
"-sl"
,
argc
,
argv
).
c_str
());
float
markerLength
=
(
float
)
atof
(
getParam
(
"-ml"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
bool
showRejected
=
false
;
if
(
isParam
(
"-r"
,
argc
,
argv
))
showRejected
=
true
;
int
squaresX
=
parser
.
get
<
int
>
(
"w"
);
int
squaresY
=
parser
.
get
<
int
>
(
"h"
);
float
squareLength
=
parser
.
get
<
float
>
(
"sl"
);
float
markerLength
=
parser
.
get
<
float
>
(
"ml"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
bool
showRejected
=
parser
.
has
(
"r"
);
bool
refindStrategy
=
parser
.
has
(
"rs"
);
int
camId
=
parser
.
get
<
int
>
(
"ci"
);
String
video
;
if
(
parser
.
has
(
"v"
))
{
video
=
parser
.
get
<
String
>
(
"v"
);
}
Mat
camMatrix
,
distCoeffs
;
if
(
isParam
(
"-c"
,
argc
,
argv
))
{
bool
readOk
=
readCameraParameters
(
getParam
(
"-c"
,
argc
,
argv
),
camMatrix
,
distCoeffs
);
if
(
parser
.
has
(
"c"
))
{
bool
readOk
=
readCameraParameters
(
parser
.
get
<
string
>
(
"c"
),
camMatrix
,
distCoeffs
);
if
(
!
readOk
)
{
cerr
<<
"Invalid camera file"
<<
endl
;
return
0
;
...
...
@@ -163,25 +142,28 @@ int main(int argc, char *argv[]) {
}
aruco
::
DetectorParameters
detectorParams
;
if
(
isParam
(
"-dp"
,
argc
,
argv
))
{
bool
readOk
=
readDetectorParameters
(
getParam
(
"-dp"
,
argc
,
argv
),
detectorParams
);
if
(
parser
.
has
(
"dp"
))
{
bool
readOk
=
readDetectorParameters
(
parser
.
get
<
string
>
(
"dp"
),
detectorParams
);
if
(
!
readOk
)
{
cerr
<<
"Invalid detector parameters file"
<<
endl
;
return
0
;
}
}
bool
refindStrategy
=
false
;
if
(
isParam
(
"-rs"
,
argc
,
argv
))
refindStrategy
=
true
;
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
VideoCapture
inputVideo
;
int
waitTime
;
if
(
isParam
(
"-v"
,
argc
,
argv
))
{
inputVideo
.
open
(
getParam
(
"-v"
,
argc
,
argv
)
);
if
(
!
video
.
empty
(
))
{
inputVideo
.
open
(
video
);
waitTime
=
0
;
}
else
{
int
camId
=
0
;
if
(
isParam
(
"-ci"
,
argc
,
argv
))
camId
=
atoi
(
getParam
(
"-ci"
,
argc
,
argv
).
c_str
());
inputVideo
.
open
(
camId
);
waitTime
=
10
;
}
...
...
@@ -251,7 +233,7 @@ int main(int argc, char *argv[]) {
if
(
interpolatedCorners
>
0
)
{
Scalar
color
;
color
=
Scalar
(
0
,
0
,
255
);
color
=
Scalar
(
255
,
0
,
0
);
aruco
::
drawDetectedCornersCharuco
(
imageCopy
,
charucoCorners
,
charucoIds
,
color
);
}
...
...
modules/aruco/samples/detect_diamonds.cpp
View file @
745d8194
...
...
@@ -46,51 +46,26 @@ using namespace std;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Detect ChArUco markers"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-sl <squareLength> # Square side lenght (in meters)"
<<
endl
;
cout
<<
"-ml <markerLength> # Marker side lenght (in meters)"
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"[-c <cameraParams>] # Camera intrinsic parameters file"
<<
endl
;
cout
<<
"[-as <float>] # Automatic scale. The provided number is multiplied by the last "
<<
"diamond id becoming an indicator of the square length. In this case, the -sl and "
<<
"-ml are only used to know the relative length relation between "
<<
"squares and markers"
<<
endl
;
cout
<<
"[-v <videoFile>] # Input from video file, if ommited, input comes from camera"
<<
endl
;
cout
<<
"[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0"
<<
endl
;
cout
<<
"[-dp <detectorParams>] # File of marker detector parameters"
<<
endl
;
cout
<<
"[-r] # show rejected candidates too"
<<
endl
;
namespace
{
const
char
*
about
=
"Detect ChArUco markers"
;
const
char
*
keys
=
"{sl | | Square side lenght (in pixels) }"
"{ml | | Marker side lenght (in pixels) }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{c | | Output file with calibrated camera parameters }"
"{as | | Automatic scale. The provided number is multiplied by the last"
"diamond id becoming an indicator of the square length. In this case, the -sl and "
"-ml are only used to know the relative length relation between squares and markers }"
"{v | | Input from video file, if ommited, input comes from camera }"
"{ci | 0 | Camera id if input doesnt come from video (-v) }"
"{dp | | File of marker detector parameters }"
"{rs | | Apply refind strategy }"
"{r | | show rejected candidates too }"
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
}
/**
*/
static
bool
readCameraParameters
(
string
filename
,
Mat
&
camMatrix
,
Mat
&
distCoeffs
)
{
...
...
@@ -136,56 +111,61 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-sl"
,
argc
,
argv
)
||
!
isParam
(
"-ml"
,
argc
,
argv
)
||
!
isParam
(
"-d"
,
argc
,
argv
)
)
{
help
();
if
(
argc
<
4
)
{
parser
.
printMessage
();
return
0
;
}
float
squareLength
=
(
float
)
atof
(
getParam
(
"-sl"
,
argc
,
argv
).
c_str
());
float
markerLength
=
(
float
)
atof
(
getParam
(
"-ml"
,
argc
,
argv
).
c_str
());
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
bool
showRejected
=
false
;
if
(
isParam
(
"-r"
,
argc
,
argv
))
showRejected
=
true
;
float
squareLength
=
parser
.
get
<
float
>
(
"sl"
);
float
markerLength
=
parser
.
get
<
float
>
(
"ml"
);
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
bool
showRejected
=
parser
.
has
(
"r"
);
bool
estimatePose
=
parser
.
has
(
"c"
);
bool
autoScale
=
parser
.
has
(
"as"
);
float
autoScaleFactor
=
autoScale
?
parser
.
get
<
float
>
(
"as"
)
:
1.
f
;
bool
estimatePose
=
false
;
Mat
camMatrix
,
distCoeffs
;
if
(
isParam
(
"-c"
,
argc
,
argv
))
{
bool
readOk
=
readCameraParameters
(
getParam
(
"-c"
,
argc
,
argv
),
camMatrix
,
distCoeffs
);
aruco
::
DetectorParameters
detectorParams
;
if
(
parser
.
has
(
"dp"
))
{
bool
readOk
=
readDetectorParameters
(
parser
.
get
<
string
>
(
"dp"
),
detectorParams
);
if
(
!
readOk
)
{
cerr
<<
"Invalid
camera
file"
<<
endl
;
cerr
<<
"Invalid
detector parameters
file"
<<
endl
;
return
0
;
}
estimatePose
=
true
;
}
bool
autoScale
=
false
;
float
autoScaleFactor
=
1.
;
if
(
isParam
(
"-as"
,
argc
,
argv
))
{
autoScaleFactor
=
(
float
)
atof
(
getParam
(
"-as"
,
argc
,
argv
).
c_str
());
autoScale
=
true
;
int
camId
=
parser
.
get
<
int
>
(
"ci"
)
;
String
video
;
if
(
parser
.
has
(
"v"
))
{
video
=
parser
.
get
<
String
>
(
"v"
)
;
}
aruco
::
DetectorParameters
detectorParams
;
if
(
isParam
(
"-dp"
,
argc
,
argv
))
{
bool
readOk
=
readDetectorParameters
(
getParam
(
"-dp"
,
argc
,
argv
),
detectorParams
);
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
Mat
camMatrix
,
distCoeffs
;
if
(
estimatePose
)
{
bool
readOk
=
readCameraParameters
(
parser
.
get
<
string
>
(
"c"
),
camMatrix
,
distCoeffs
);
if
(
!
readOk
)
{
cerr
<<
"Invalid
detector parameters
file"
<<
endl
;
cerr
<<
"Invalid
camera
file"
<<
endl
;
return
0
;
}
}
VideoCapture
inputVideo
;
int
waitTime
;
if
(
isParam
(
"-v"
,
argc
,
argv
))
{
inputVideo
.
open
(
getParam
(
"-v"
,
argc
,
argv
)
);
if
(
!
video
.
empty
(
))
{
inputVideo
.
open
(
video
);
waitTime
=
0
;
}
else
{
int
camId
=
0
;
if
(
isParam
(
"-ci"
,
argc
,
argv
))
camId
=
atoi
(
getParam
(
"-ci"
,
argc
,
argv
).
c_str
());
inputVideo
.
open
(
camId
);
waitTime
=
10
;
}
...
...
@@ -224,7 +204,7 @@ int main(int argc, char *argv[]) {
for
(
unsigned
int
i
=
0
;
i
<
diamondCorners
.
size
();
i
++
)
{
float
autoSquareLength
=
autoScaleFactor
*
float
(
diamondIds
[
i
].
val
[
3
]);
vector
<
vector
<
Point2f
>
>
currentCorners
;
vector
<
Mat
>
currentRvec
,
currentTvec
;
vector
<
Vec3d
>
currentRvec
,
currentTvec
;
currentCorners
.
push_back
(
diamondCorners
[
i
]);
aruco
::
estimatePoseSingleMarkers
(
currentCorners
,
autoSquareLength
,
camMatrix
,
distCoeffs
,
currentRvec
,
currentTvec
);
...
...
modules/aruco/samples/detect_markers.cpp
View file @
745d8194
...
...
@@ -39,56 +39,26 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp>
#include <vector>
#include <iostream>
using
namespace
std
;
using
namespace
cv
;
/**
*/
static
void
help
()
{
cout
<<
"Basic marker detection"
<<
endl
;
cout
<<
"Parameters: "
<<
endl
;
cout
<<
"-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, "
<<
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<<
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<<
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16"
<<
endl
;
cout
<<
"[-v <videoFile>] # Input from video file, if ommited, input comes from camera"
<<
endl
;
cout
<<
"[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0"
<<
endl
;
cout
<<
"[-c <cameraParams>] # Camera intrinsic parameters. Needed for camera pose"
<<
endl
;
cout
<<
"[-l <markerLength>] # Marker side lenght (in meters). Needed for correct"
<<
"scale in camera pose, default 0.1"
<<
endl
;
cout
<<
"[-dp <detectorParams>] # File of marker detector parameters"
<<
endl
;
cout
<<
"[-r] # show rejected candidates too"
<<
endl
;
}
/**
*/
static
bool
isParam
(
string
param
,
int
argc
,
char
**
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
return
true
;
return
false
;
namespace
{
const
char
*
about
=
"Basic marker detection"
;
const
char
*
keys
=
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{v | | Input from video file, if ommited, input comes from camera }"
"{ci | 0 | Camera id if input doesnt come from video (-v) }"
"{c | | Camera intrinsic parameters. Needed for camera pose }"
"{l | 0.1 | Marker side lenght (in meters). Needed for correct scale in camera pose }"
"{dp | | File of marker detector parameters }"
"{r | | show rejected candidates too }"
;
}
/**
*/
static
string
getParam
(
string
param
,
int
argc
,
char
**
argv
,
string
defvalue
=
""
)
{
int
idx
=
-
1
;
for
(
int
i
=
0
;
i
<
argc
&&
idx
==
-
1
;
i
++
)
if
(
string
(
argv
[
i
])
==
param
)
idx
=
i
;
if
(
idx
==
-
1
||
(
idx
+
1
)
>=
argc
)
return
defvalue
;
else
return
argv
[
idx
+
1
];
}
/**
*/
static
bool
readCameraParameters
(
string
filename
,
Mat
&
camMatrix
,
Mat
&
distCoeffs
)
{
...
...
@@ -136,49 +106,59 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/**
*/
int
main
(
int
argc
,
char
*
argv
[])
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
if
(
!
isParam
(
"-d"
,
argc
,
argv
)
)
{
help
();
if
(
argc
<
2
)
{
parser
.
printMessage
();
return
0
;
}
int
dictionaryId
=
atoi
(
getParam
(
"-d"
,
argc
,
argv
).
c_str
());
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
bool
showRejected
=
false
;
if
(
isParam
(
"-r"
,
argc
,
argv
))
showRejected
=
true
;
int
dictionaryId
=
parser
.
get
<
int
>
(
"d"
);
bool
showRejected
=
parser
.
has
(
"r"
);
bool
estimatePose
=
parser
.
has
(
"c"
);
float
markerLength
=
parser
.
get
<
float
>
(
"l"
);
bool
estimatePose
=
false
;
Mat
camMatrix
,
distCoeffs
;
if
(
isParam
(
"-c"
,
argc
,
argv
))
{
bool
readOk
=
readCameraParameters
(
getParam
(
"-c"
,
argc
,
argv
),
camMatrix
,
distCoeffs
);
aruco
::
DetectorParameters
detectorParams
;
if
(
parser
.
has
(
"dp"
))
{
bool
readOk
=
readDetectorParameters
(
parser
.
get
<
string
>
(
"dp"
),
detectorParams
);
if
(
!
readOk
)
{
cerr
<<
"Invalid
camera
file"
<<
endl
;
cerr
<<
"Invalid
detector parameters
file"
<<
endl
;
return
0
;
}
estimatePose
=
true
;
}
float
markerLength
=
(
float
)
atof
(
getParam
(
"-l"
,
argc
,
argv
,
"0.1"
).
c_str
());
detectorParams
.
doCornerRefinement
=
true
;
// do corner refinement in markers
int
camId
=
parser
.
get
<
int
>
(
"ci"
);
String
video
;
if
(
parser
.
has
(
"v"
))
{
video
=
parser
.
get
<
String
>
(
"v"
);
}
aruco
::
DetectorParameters
detectorParams
;
if
(
isParam
(
"-dp"
,
argc
,
argv
))
{
bool
readOk
=
readDetectorParameters
(
getParam
(
"-dp"
,
argc
,
argv
),
detectorParams
);
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
aruco
::
Dictionary
dictionary
=
aruco
::
getPredefinedDictionary
(
aruco
::
PREDEFINED_DICTIONARY_NAME
(
dictionaryId
));
Mat
camMatrix
,
distCoeffs
;
if
(
estimatePose
)
{
bool
readOk
=
readCameraParameters
(
parser
.
get
<
string
>
(
"c"
),
camMatrix
,
distCoeffs
);
if
(
!
readOk
)
{
cerr
<<
"Invalid
detector parameters
file"
<<
endl
;
cerr
<<
"Invalid
camera
file"
<<
endl
;
return
0
;
}
}
detectorParams
.
doCornerRefinement
=
true
;
// do corner refinement in markers
VideoCapture
inputVideo
;
int
waitTime
;
if
(
isParam
(
"-v"
,
argc
,
argv
))
{
inputVideo
.
open
(
getParam
(
"-v"
,
argc
,
argv
)
);
if
(
!
video
.
empty
(
))
{
inputVideo
.
open
(
video
);
waitTime
=
0
;
}
else
{
int
camId
=
0
;
if
(
isParam
(
"-ci"
,
argc
,
argv
))
camId
=
atoi
(
getParam
(
"-ci"
,
argc
,
argv
).
c_str
());
inputVideo
.
open
(
camId
);
waitTime
=
10
;
}
...
...
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