Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions WebARKit/WebARKitManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,8 @@ bool WebARKitManager::isValid() {
return m_tracker->isValid();
}

void WebARKitManager::setOriginCentered(bool centered) {
m_tracker->setOriginCentered(centered);
}

} // namespace webarkit
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WebARKitTracker::WebARKitTrackerImpl {
: corners(4), initialized(false), output(17, 0.0), _valid(false), _maxNumberOfMarkersToTrack(1),
_currentlyTrackedMarkers(0), _frameCount(0), _frameSizeX(0),
_frameSizeY(0),
_isDetected(false), _isTracking(false), numMatches(0),
_isDetected(false), _isTracking(false), _centerOrigin(false), numMatches(0),
minNumMatches(MIN_NUM_MATCHES), _nn_match_ratio(0.7f), _trackVizActive(false),
_trackViz(TrackerVisualization()) {
m_camMatrix = cv::Matx33d::zeros();
Expand Down Expand Up @@ -181,6 +181,10 @@ class WebARKitTracker::WebARKitTrackerImpl {

bool isValid() { return _valid; };

// WebARKitLib#38: when true, the pose origin is the marker centre instead of
// the reference image's top-left corner. Default false (ArtoolkitX parity).
void setOriginCentered(bool centered) { _centerOrigin = centered; };

protected:
bool RunTemplateMatching(cv::Mat frame, int trackableId) {
// std::cout << "Starting template match" << std::endl;
Expand Down Expand Up @@ -384,6 +388,19 @@ class WebARKitTracker::WebARKitTrackerImpl {
cv::Mat _pose;
std::vector<cv::Point2f> imgPoints = _trackSelection.GetTrackedFeaturesWarped();
std::vector<cv::Point3f> objPoints = _trackSelection.GetTrackedFeatures3d();
// WebARKitLib#38 (webarkit-testing#38): optional centered origin. When
// enabled, shift the 3D object points so the pose origin is the marker
// centre instead of the reference image's top-left corner -- content at
// (0,0,0) then sits in the middle of the marker. Offsetting the object
// points moves only the solved translation; the rotation is unchanged.
// Applied to the solvePnP points ONLY -- the 2D imgPoints and the
// matching/template/homography paths stay in raw image space. Default
// off (ArtoolkitX parity). See docs/design-center-origin-option.md.
if (_centerOrigin) {
const float cx = _pattern.size.width * 0.5f;
const float cy = _pattern.size.height * 0.5f;
for (auto& p : objPoints) { p.x -= cx; p.y -= cy; }
}
// Need at least 4 correspondences for solvePnP, and the two sets must
// match in size. On the very first frame a marker can be detected
// before the tracked-point selection is populated (the optical-flow
Expand Down Expand Up @@ -703,6 +720,9 @@ class WebARKitTracker::WebARKitTrackerImpl {

bool _isTracking;

// WebARKitLib#38: pose origin = marker centre when true (default false).
bool _centerOrigin;

std::vector<cv::Point2f> corners;

cv::Mat m_H;
Expand Down Expand Up @@ -822,4 +842,6 @@ std::array<double, 16> WebARKitTracker::getCameraProjectionMatrix() {

bool WebARKitTracker::isValid() { return _trackerImpl->isValid(); }

void WebARKitTracker::setOriginCentered(bool centered) { _trackerImpl->setOriginCentered(centered); }

} // namespace webarkit
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class WebARKitTracker {

bool isValid();

// WebARKitLib#38: pose origin = marker centre when true (default false).
void setOriginCentered(bool centered);

private:
class WebARKitTrackerImpl;

Expand Down
3 changes: 3 additions & 0 deletions WebARKit/include/WebARKitManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class WebARKitManager {
std::array<double, 16> getCameraProjectionMatrix();

bool isValid();

/// WebARKitLib#38: pose origin = marker centre when true (default false).
void setOriginCentered(bool centered);
};

} // namespace webarkit
Expand Down