Skip to content

Commit 051b1f4

Browse files
author
AleksandrPanov
committed
remove global ArUco3 params (threshold)
1 parent a0e036a commit 051b1f4

File tree

7 files changed

+148
-288
lines changed

7 files changed

+148
-288
lines changed

modules/aruco/include/opencv2/aruco.hpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,7 @@ enum CornerRefineMethod{
163163
* Latter is the binarized image in which contours are searched.
164164
* So all contours with a size smaller than minSideLengthCanonicalImg*minSideLengthCanonicalImg will omitted from the search.
165165
* - minMarkerLengthRatioOriginalImg: range [0,1], eq (2) from paper
166-
* - cameraMotionSpeed: is in the range [0,1]. This parameter (tau_s in the paper) implements the feature proposed
167-
* in Section 3.7. and is particularly useful for video sequences.
168-
* The parameter tau_i has a direct influence on the processing speed. Instead of setting a fixed value for it,
169-
* it can be adjusted at the end of each frame using
170-
* tau_i = (1-tau_s)*P(v_s)/4 (eq. 6 in paper).
171-
* Where P(v_s) is the perimeter of the smallest marker that was detected in the last frame.
172-
* - useGlobalThreshold: if we process a video, the assumption is, that the illumination conditions remains
173-
* constant and global instead of adaptive thresholding can be applied, speeding up the binarization step.
174-
* - foundGlobalThreshold: internal variable. It is used to cache the variable to the next detector call.
175-
* - otsuGlobalThreshold: internal variable. It is used to cache the global otsu threshold to the next detector call.
176-
* - foundMarkerInLastFrames: internal variable. It is used to cache if markers were found in the last frame.
166+
* The parameter tau_i has a direct influence on the processing speed.
177167
*/
178168
struct CV_EXPORTS_W DetectorParameters {
179169

@@ -222,13 +212,6 @@ struct CV_EXPORTS_W DetectorParameters {
222212
CV_PROP_RW bool useAruco3Detection;
223213
CV_PROP_RW int minSideLengthCanonicalImg;
224214
CV_PROP_RW float minMarkerLengthRatioOriginalImg;
225-
226-
// New Aruco functionality especially for video
227-
CV_PROP_RW float cameraMotionSpeed;
228-
CV_PROP_RW bool useGlobalThreshold;
229-
CV_PROP_RW bool foundGlobalThreshold;
230-
CV_PROP_RW float otsuGlobalThreshold;
231-
CV_PROP_RW int foundMarkerInLastFrames;
232215
};
233216

234217

@@ -256,13 +239,12 @@ struct CV_EXPORTS_W DetectorParameters {
256239
* are searched. For each detected marker, it returns the 2D position of its corner in the image
257240
* and its corresponding identifier.
258241
* Note that this function does not perform pose estimation.
259-
* The function returns an estimate of the parameter minMarkerLengthRatioOriginalImg if useAruco3Detection=1. If not it returns 0.0.
260-
* @sa estimatePoseSingleMarkers, estimatePoseBoard
242+
* @sa estimatePoseSingleMarkers, estimatePoseBoard
261243
*
262244
*/
263-
CV_EXPORTS_W float detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
264-
OutputArray ids, const Ptr<DetectorParameters> &parameters = DetectorParameters::create(),
265-
OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray());
245+
CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
246+
OutputArray ids, const Ptr<DetectorParameters> &parameters = DetectorParameters::create(),
247+
OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray());
266248

267249

268250

modules/aruco/perf/perf_aruco.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,22 @@ class MarkerPainter
155155
static inline double getMaxDistance(map<int, vector<Point2f> > &golds, const vector<int>& ids,
156156
const vector<vector<Point2f> >& corners)
157157
{
158-
double distance = 0.;
158+
std::map<int, double> mapDist;
159+
for (const auto& el : golds)
160+
mapDist[el.first] = std::numeric_limits<double>::max();
159161
for (size_t i = 0; i < ids.size(); i++)
160162
{
161163
int id = ids[i];
162164
const auto gold_corners = golds.find(id);
163-
if (gold_corners != golds.end())
164-
for (int c = 0; c < 4; c++)
165-
distance = std::max(distance, cv::norm(gold_corners->second[c] - corners[i][c]));
165+
if (gold_corners != golds.end()) {
166+
double distance = 0.;
167+
for (int c = 0; c < 4; c++)
168+
distance = std::max(distance, cv::norm(gold_corners->second[c] - corners[i][c]));
169+
mapDist[id] = distance;
170+
}
166171
}
167-
return distance;
172+
return std::max_element(std::begin(mapDist), std::end(mapDist),
173+
[](const pair<int, double>& p1, const pair<int, double>& p2){return p1.second < p2.second;})->second;
168174
}
169175

170176
PERF_TEST_P(EstimateAruco, ArucoFirst, ESTIMATE_PARAMS)
@@ -190,7 +196,7 @@ PERF_TEST_P(EstimateAruco, ArucoFirst, ESTIMATE_PARAMS)
190196
// detect markers
191197
vector<vector<Point2f> > corners;
192198
vector<int> ids;
193-
TEST_CYCLE_N(10)
199+
TEST_CYCLE()
194200
{
195201
aruco::detectMarkers(image_map.first, dictionary, corners, ids, detectorParams);
196202
}
@@ -223,7 +229,7 @@ PERF_TEST_P(EstimateAruco, ArucoSecond, ESTIMATE_PARAMS)
223229
// detect markers
224230
vector<vector<Point2f> > corners;
225231
vector<int> ids;
226-
TEST_CYCLE_N(10)
232+
TEST_CYCLE()
227233
{
228234
aruco::detectMarkers(image_map.first, dictionary, corners, ids, detectorParams);
229235
}
@@ -278,7 +284,7 @@ PERF_TEST_P(EstimateLargeAruco, ArucoFHD, ESTIMATE_FHD_PARAMS)
278284
// detect markers
279285
vector<vector<Point2f> > corners;
280286
vector<int> ids;
281-
TEST_CYCLE_N(10)
287+
TEST_CYCLE()
282288
{
283289
aruco::detectMarkers(image_map.first, dictionary, corners, ids, detectorParams);
284290
}
@@ -288,4 +294,4 @@ PERF_TEST_P(EstimateLargeAruco, ArucoFHD, ESTIMATE_FHD_PARAMS)
288294
SANITY_CHECK_NOTHING();
289295
}
290296

291-
}
297+
}

modules/aruco/samples/detect_markers.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ const char* keys =
6363
"{dp | | File of marker detector parameters }"
6464
"{r | | show rejected candidates too }"
6565
"{refine | | Corner refinement: CORNER_REFINE_NONE=0, CORNER_REFINE_SUBPIX=1,"
66-
"CORNER_REFINE_CONTOUR=2, CORNER_REFINE_APRILTAG=3}"
67-
"{ar3vid | | Adapt the paramater tau_i if aruco3 functionality is used. }";
66+
"CORNER_REFINE_CONTOUR=2, CORNER_REFINE_APRILTAG=3}";
6867
}
6968
//! [aruco_detect_markers_keys]
7069

@@ -80,7 +79,6 @@ int main(int argc, char *argv[]) {
8079
bool showRejected = parser.has("r");
8180
bool estimatePose = parser.has("c");
8281
float markerLength = parser.get<float>("l");
83-
bool useAruco3DynamicUpdates = parser.has("ar3vid");
8482

8583
Ptr<aruco::DetectorParameters> detectorParams;
8684
if(parser.has("dp")) {
@@ -141,7 +139,7 @@ int main(int argc, char *argv[]) {
141139
int waitTime;
142140
if(!video.empty()) {
143141
inputVideo.open(video);
144-
waitTime = 1;
142+
waitTime = 0;
145143
} else {
146144
inputVideo.open(camId);
147145
waitTime = 10;
@@ -150,8 +148,6 @@ int main(int argc, char *argv[]) {
150148
double totalTime = 0;
151149
int totalIterations = 0;
152150

153-
float new_marker_length_ratio = 0.0;
154-
size_t total_nr_detected_corners = 0;
155151
while(inputVideo.grab()) {
156152
Mat image, imageCopy;
157153
inputVideo.retrieve(image);
@@ -163,16 +159,7 @@ int main(int argc, char *argv[]) {
163159
vector< Vec3d > rvecs, tvecs;
164160

165161
// detect markers and estimate pose
166-
if (useAruco3DynamicUpdates) {
167-
// if new aruco3 features are used, we can also set the new min
168-
// marker length ratio dymamically from the last frame
169-
detectorParams->minMarkerLengthRatioOriginalImg = new_marker_length_ratio;
170-
if(totalIterations % 30 == 0) {
171-
cout<<"Current tau_i= "<<new_marker_length_ratio<<"\n";
172-
}
173-
}
174-
new_marker_length_ratio = aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
175-
total_nr_detected_corners += ids.size();
162+
aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
176163
if(estimatePose && ids.size() > 0)
177164
aruco::estimatePoseSingleMarkers(corners, markerLength, camMatrix, distCoeffs, rvecs,
178165
tvecs);

modules/aruco/samples/detector_params.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ maxErroneousBitsInBorderRate: 0.04
2222
minOtsuStdDev: 5.0
2323
errorCorrectionRate: 0.6
2424

25-
# new aruco functionality
25+
# new aruco 3 functionality
2626
useAruco3Detection: 0
2727
minSideLengthCanonicalImg: 32 # 16, 32, 64 --> tau_c from the paper
2828
minMarkerLengthRatioOriginalImg: 0.02 # range [0,0.2] --> tau_i from the paper

0 commit comments

Comments
 (0)