Skip to content

Commit

Permalink
fixed merge conflict with 'marker-rot-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
internaut committed Jul 28, 2014
2 parents 86da244 + 04c9c30 commit e804d21
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 85 deletions.
5 changes: 4 additions & 1 deletion ident_7x7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions ident_templ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
34 changes: 2 additions & 32 deletions marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <otherMrk>
float minAvgDist = numeric_limits<float>::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 <otherMrk>
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() {
Expand Down Expand Up @@ -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];
Expand Down
16 changes: 5 additions & 11 deletions marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <otherMrk>'s vertex points.
*/
void mapPoints(const Marker &otherMrk);

/**
* Set the points in <pVec>.
*/
Expand All @@ -103,6 +97,11 @@ class Marker {
*/
void clearPoints() { points.clear(); }

/**
* Rotate the corner points in the vector <rot> times.
*/
void rotatePoints(int rot);

/**
* Return the controid calculated from the corner points.
*/
Expand Down Expand Up @@ -152,11 +151,6 @@ class Marker {
*/
void sortPoints();

/**
* Rotate the corner points in the vector <rot> times.
*/
void rotatePoints(int rot);

/**
* Calculate the shape properties from the corner points like centroid
* and perimeter radius.
Expand Down
33 changes: 0 additions & 33 deletions track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -127,33 +124,3 @@ void Track::update() {

unlockMarkers(); // unlock markers map
}

#pragma mark private methods

void Track::correctMarkerVertexOrder(std::vector<Marker *> 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<Marker *>::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);
}
}
}
}
8 changes: 0 additions & 8 deletions track.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ class Track {
const MarkerMap *getMarkers() const { return &markers; }

private:
/**
* Correct the marker vertex order of the markers in <newMarkers> by mapping
* their corner points to already existing markers. This is important to
* have a stable marker vertex point order.
*/
void correctMarkerVertexOrder(std::vector<Marker *> newMarkers);


std::vector<Marker> 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
Expand Down

0 comments on commit e804d21

Please sign in to comment.