@@ -480,10 +480,11 @@ static int _getBorderErrors(const Mat &bits, int markerSize, int borderSize) {
480
480
/* *
481
481
* @brief Tries to identify one candidate given the dictionary
482
482
*/
483
- static bool _identifyOneCandidate (const Ptr<Dictionary> &dictionary, InputArray _image,
484
- InputOutputArray _corners, int &idx, const Ptr<DetectorParameters> ¶ms) {
485
-
486
- CV_Assert (_corners.total () == 4 );
483
+ static bool _identifyOneCandidate (const Ptr<Dictionary>& dictionary, InputArray _image,
484
+ vector<Point2f>& _corners, int & idx,
485
+ const Ptr<DetectorParameters>& params)
486
+ {
487
+ CV_Assert (_corners.size () == 4 );
487
488
CV_Assert (_image.getMat ().total () != 0 );
488
489
CV_Assert (params->markerBorderBits > 0 );
489
490
@@ -510,16 +511,12 @@ static bool _identifyOneCandidate(const Ptr<Dictionary> &dictionary, InputArray
510
511
int rotation;
511
512
if (!dictionary->identify (onlyBits, idx, rotation, params->errorCorrectionRate ))
512
513
return false ;
513
- else {
514
- // shift corner positions to the correct rotation
515
- if (rotation != 0 ) {
516
- Mat copyPoints = _corners.getMat ().clone ();
517
- for (int j = 0 ; j < 4 ; j++)
518
- _corners.getMat ().ptr < Point2f >(0 )[j] =
519
- copyPoints.ptr < Point2f >(0 )[(j + 4 - rotation) % 4 ];
520
- }
521
- return true ;
514
+
515
+ // shift corner positions to the correct rotation
516
+ if (rotation != 0 ) {
517
+ std::rotate (_corners.begin (), _corners.begin () + 4 - rotation, _corners.end ());
522
518
}
519
+ return true ;
523
520
}
524
521
525
522
@@ -529,11 +526,11 @@ static bool _identifyOneCandidate(const Ptr<Dictionary> &dictionary, InputArray
529
526
*/
530
527
class IdentifyCandidatesParallel : public ParallelLoopBody {
531
528
public:
532
- IdentifyCandidatesParallel (const Mat& _grey, InputArrayOfArrays _candidates,
533
- InputArrayOfArrays _contours, const Ptr<Dictionary> &_dictionary,
529
+ IdentifyCandidatesParallel (const Mat& _grey, vector< vector< Point2f > >& _candidates,
530
+ const Ptr<Dictionary> &_dictionary,
534
531
vector< int >& _idsTmp, vector< char >& _validCandidates,
535
532
const Ptr<DetectorParameters> &_params)
536
- : grey(_grey), candidates(_candidates), contours(_contours), dictionary(_dictionary),
533
+ : grey(_grey), candidates(_candidates), dictionary(_dictionary),
537
534
idsTmp (_idsTmp), validCandidates(_validCandidates), params(_params) {}
538
535
539
536
void operator ()(const Range &range) const {
@@ -542,8 +539,7 @@ class IdentifyCandidatesParallel : public ParallelLoopBody {
542
539
543
540
for (int i = begin; i < end; i++) {
544
541
int currId;
545
- Mat currentCandidate = candidates.getMat (i);
546
- if (_identifyOneCandidate (dictionary, grey, currentCandidate, currId, params)) {
542
+ if (_identifyOneCandidate (dictionary, grey, candidates[i], currId, params)) {
547
543
validCandidates[i] = 1 ;
548
544
idsTmp[i] = currId;
549
545
}
@@ -554,7 +550,7 @@ class IdentifyCandidatesParallel : public ParallelLoopBody {
554
550
IdentifyCandidatesParallel &operator =(const IdentifyCandidatesParallel &); // to quiet MSVC
555
551
556
552
const Mat &grey;
557
- InputArrayOfArrays candidates, contours ;
553
+ vector< vector< Point2f > >& candidates ;
558
554
const Ptr<Dictionary> &dictionary;
559
555
vector< int > &idsTmp;
560
556
vector< char > &validCandidates;
@@ -634,7 +630,7 @@ static void _identifyCandidates(InputArray _image, vector< vector< Point2f > >&
634
630
635
631
// this is the parallel call for the previous commented loop (result is equivalent)
636
632
parallel_for_ (Range (0 , ncandidates),
637
- IdentifyCandidatesParallel (grey, _candidates, _contours, _dictionary, idsTmp,
633
+ IdentifyCandidatesParallel (grey, _candidates, _dictionary, idsTmp,
638
634
validCandidates, params));
639
635
640
636
for (int i = 0 ; i < ncandidates; i++) {
0 commit comments