diff --git a/ident_7x7.cpp b/ident_7x7.cpp index d2039c9..0c33530 100644 --- a/ident_7x7.cpp +++ b/ident_7x7.cpp @@ -55,17 +55,20 @@ bool Identificator7x7::readMarkerCode(const cv::Mat &area, Marker &marker) { } // check marker code for all possible 4 rotations +// printf("---\n"); for (int rot = 0; rot < 4; rot++) { if (checkMarkerCode(bitMatrix)) { // found a valid marker code! // set the id and rotate the corner points int id = markerCodeToId(bitMatrix); marker.setId(id); - + marker.rotatePoints(rot); + return true; } Tools::matRot90CW(bitMatrix); // rotate the matrix } +// printf("---\n"); return false; } diff --git a/ident_templ.cpp b/ident_templ.cpp index 835d802..91efb09 100644 --- a/ident_templ.cpp +++ b/ident_templ.cpp @@ -71,6 +71,7 @@ bool IdentificatorTemplMatch::readMarkerCode(const cv::Mat &area, Marker &marker int validRot; if (checkTemplateRotations(areaContent, it->second, &validRot)) { // found a matching template! marker.setId(it->first); + marker.rotatePoints(validRot); return true; } } diff --git a/marker.cpp b/marker.cpp index 751aa4f..9316382 100644 --- a/marker.cpp +++ b/marker.cpp @@ -60,34 +60,8 @@ Marker::~Marker() { if (tVecHist) delete [] tVecHist; } -void Marker::mapPoints(const ocv_ar::Marker &otherMrk) { - Point2fVec otherPts = otherMrk.getPoints(); - - int rotBy = 0; - - // find the rotation the rotation that yields minimum average distance - // between the vertex points of this marker and - float minAvgDist = numeric_limits::max(); - for (int rot = 0; rot < 4; ++rot) { // for each possible rotation - float avgDist = 0.0f; - for (int p = 0; p < 4; ++p) { // for each vertex point - // calculate squared distance to the (rotated) other vertex - avgDist += Tools::distSquared(points[p], otherPts[(p + rot) % 4]); - } - - avgDist /= 4; - - if (avgDist < minAvgDist) { - minAvgDist = avgDist; - rotBy = rot; - } - } - - // rotate our points to match the vertex order of - if (rotBy > 0) { -// printf("ocv_ar::Marker %d - rotating vertices by %d with min. avg. dist. %f\n", id, rotBy, minAvgDist); - rotatePoints(rotBy); - } +void Marker::rotatePoints(int rot) { + rotate(points.begin(), points.begin() + rot + 1, points.end()); } void Marker::updateDetectionTime() { @@ -170,10 +144,6 @@ void Marker::init() { updateDetectionTime(); // set to now } -void Marker::rotatePoints(int rot) { - rotate(points.begin(), points.begin() + 4 - rot, points.end()); -} - void Marker::sortPoints() { // Sort the points in anti-clockwise order cv::Point v1 = points[1] - points[0]; diff --git a/marker.h b/marker.h index 3c0352d..fb44b6e 100644 --- a/marker.h +++ b/marker.h @@ -82,12 +82,6 @@ class Marker { */ Point2fVec getPoints() const { return points; } - /** - * Rotate the vertices (the points vector) so that this marker's points - * match up with 's vertex points. - */ - void mapPoints(const Marker &otherMrk); - /** * Set the points in . */ @@ -103,6 +97,11 @@ class Marker { */ void clearPoints() { points.clear(); } + /** + * Rotate the corner points in the vector times. + */ + void rotatePoints(int rot); + /** * Return the controid calculated from the corner points. */ @@ -152,11 +151,6 @@ class Marker { */ void sortPoints(); - /** - * Rotate the corner points in the vector times. - */ - void rotatePoints(int rot); - /** * Calculate the shape properties from the corner points like centroid * and perimeter radius. diff --git a/track.cpp b/track.cpp index 3e1ca53..aea48a7 100644 --- a/track.cpp +++ b/track.cpp @@ -31,9 +31,6 @@ void Track::detect(const cv::Mat *frame) { lockMarkers(); // lock markers map - // correct the vertices of the found markers - correctMarkerVertexOrder(detector->getMarkers()); - // estimate the markers' 3D poses detector->estimateMarkersPoses(); @@ -127,33 +124,3 @@ void Track::update() { unlockMarkers(); // unlock markers map } - -#pragma mark private methods - -void Track::correctMarkerVertexOrder(std::vector newMarkers) { - // map the vertex order of currently found markers to previously found - // markers. this prevents the vertex order from jumping around and - // therefore changing the rotation vector of the markers - - // note that lockMarkers() needs to be called before! - - for (MarkerMap::const_iterator it = markers.begin(); - it != markers.end(); - ++it) - { - int existingMrkId = it->first; - - // try to find a matching marker in the "new markers" vector - for (vector::iterator newMrkIt = newMarkers.begin(); - newMrkIt != newMarkers.end(); - ++newMrkIt) - { - Marker *newMrk = *newMrkIt; - if (existingMrkId == newMrk->getId()) { // we found a matching marker - // update the new marker so that the order of vertices matches to - // the existing marker - newMrk->mapPoints(it->second); - } - } - } -} \ No newline at end of file diff --git a/track.h b/track.h index 21d3868..0ea028d 100644 --- a/track.h +++ b/track.h @@ -77,14 +77,6 @@ class Track { const MarkerMap *getMarkers() const { return &markers; } private: - /** - * Correct the marker vertex order of the markers in by mapping - * their corner points to already existing markers. This is important to - * have a stable marker vertex point order. - */ - void correctMarkerVertexOrder(std::vector newMarkers); - - std::vector newMarkers; // vector that holds Marker objects from the // last time when detect() was called bool newMarkersFresh; // is true if detect() was called before and is set