Skip to content

Feature webarkit trackers and beyond -> PlanarTracker integration #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
70eb898
restoring ARMulti
kalwalt May 14, 2020
0947a3a
video.c for javascript5 and similar
kalwalt May 14, 2020
c315ed5
removing other not necessary files
kalwalt May 15, 2020
6773be1
android.h is not necessary
kalwalt May 15, 2020
7946e7a
removing AR/gsub_es.h, gsub_es2.h, gsub_lite.h
kalwalt May 15, 2020
c390f77
removing Eden lib
kalwalt May 15, 2020
f04ec81
removing gsub.h and gsubConfig.h
kalwalt May 15, 2020
fcf13e2
Merge branch 'dev'
kalwalt Jan 17, 2022
683d401
Merge branch 'fix-webarkitLog'
kalwalt Apr 1, 2022
1462dd4
merge dev with auto_ptr fix
kalwalt Nov 12, 2022
0f4a704
removing dynamic throw's see #11
kalwalt Nov 28, 2022
6074362
adding try catch to avoid dynamic throw #11
kalwalt Nov 28, 2022
8f42e14
removing dymanic throw from image.h & .cpp see #11
kalwalt Nov 29, 2022
20c369f
Eigen 3.4.0 version
kalwalt Jun 30, 2022
0472a3d
added fatal log errors
kalwalt Nov 30, 2022
07baf8b
updated Readme
kalwalt Nov 30, 2022
0eb8bc1
removing config.h
kalwalt Nov 30, 2022
63d3f05
WebARKitTrackers from
kalwalt Apr 25, 2023
1de18a2
free() is not needed at all
kalwalt Apr 27, 2023
018c055
better processFrame functions
kalwalt May 1, 2023
5237407
move track method to WebARKitTracker class
kalwalt May 1, 2023
323b6df
simplified code: removing WebARKitAkazeTracker and
kalwalt May 1, 2023
3c33128
clang-formatting
kalwalt May 2, 2023
0029a16
default destructor
kalwalt May 4, 2023
210a7ed
implementing pImpl pattern - WebARKitTracker class
kalwalt May 4, 2023
03b8f4e
copy and move constructors
kalwalt May 4, 2023
c876779
New HarrisDetector and WebARKItFeatureDetector
kalwalt May 10, 2023
831fada
createFeatureMask method
kalwalt May 10, 2023
f98b9c0
adapted code from artoolkitx
kalwalt May 10, 2023
c9246e4
SelectTrackablesPoints, RunOpticalFlow and
kalwalt May 10, 2023
0abe7f4
other methods:
kalwalt May 10, 2023
0d02b23
ProcessFrameData_w and other functions
kalwalt May 10, 2023
045d4fe
new loadARParam, IsTrackableVisible
kalwalt May 12, 2023
63b56c4
some debug messages
kalwalt May 12, 2023
6c3d0c6
some cout's for debugging and provide
kalwalt May 13, 2023
4e3ce3a
fix for isssue with _maxNumberOfMarkersToTrack
kalwalt May 14, 2023
9769ce8
getTrackablePosePtr and termcrit as const
kalwalt May 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include/AR/config.h
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# WebARKitLib

The C/C++ source code of WebARKit, from Artoolkit5 and extended.
Updated to [Eigen](https://eigen.tuxfamily.org) 3.4.0 and Emscripten emsdk 3.1.26.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* HarrisDetector.cpp
* WebARkit
*
* This file is part of WebARkit.
*
* WebARkit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebARkit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with WebARkit. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent modules, and to
* copy and distribute the resulting executable under terms of your choice,
* provided that you also meet, for each linked independent module, the terms and
* conditions of the license of that module. An independent module is a module
* which is neither derived from nor based on this library. If you modify this
* library, you may extend this exception to your version of the library, but you
* are not obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Copyright 2018 Realmax, Inc.
* Copyright 2015 Daqri, LLC.
* Copyright 2010-2015 ARToolworks, Inc.
* Copyright 2023 WebARKit
*
* Author(s): Philip Lamb, Daniel Bell, Walter Perdan
*
* This code was taken from artoolkitX https://github.com/artoolkitx/artoolkitx
* with small modifications to adapt to existing WebARKIt code.
*
*/

#include <WebARKitTrackers/WebARKitOpticalTracking/HarrisDetector.h>

HarrisDetector::HarrisDetector() {
_termcrit = cv::TermCriteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, 20, 0.03);
}

std::vector<cv::Point2f> HarrisDetector::FindCorners(cv::Mat gray) {
// Mask out a border of width harrisBorder.
cv::Mat mask = cv::Mat::zeros(gray.size(), CV_8UC1);
cv::Rect innerRegion(harrisBorder, harrisBorder, gray.cols - (harrisBorder * 2), gray.rows - (harrisBorder * 2));
cv::Mat maskRoi = mask(innerRegion);
maskRoi.setTo(cv::Scalar(255));

std::vector<cv::Point2f> trackablePointsWarped;
goodFeaturesToTrack(gray, trackablePointsWarped, MAX_COUNT, 0.1, 10, mask, 3, false, 0.04);

mask.release();

return trackablePointsWarped;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* HomographyInfo.cpp
* WebARKit
*
* This file is part of WebARKit.
*
* WebARKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebARKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with WebARKit. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent modules, and to
* copy and distribute the resulting executable under terms of your choice,
* provided that you also meet, for each linked independent module, the terms and
* conditions of the license of that module. An independent module is a module
* which is neither derived from nor based on this library. If you modify this
* library, you may extend this exception to your version of the library, but you
* are not obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Copyright 2018 Realmax, Inc.
* Copyright 2015 Daqri, LLC.
* Copyright 2010-2015 ARToolworks, Inc.
* Copyright 2023 WebARKit
*
* Author(s): Philip Lamb, Daniel Bell, Walter Perdan
*
* This code was taken from artoolkitX https://github.com/artoolkitx/artoolkitx
* with small modifications to adapt to existing WebARKIt code.
*
*/
#include <WebARKitTrackers/WebARKitOpticalTracking/HomographyInfo.h>

HomographyInfo::HomographyInfo()
{
validHomography = false;
}

HomographyInfo::HomographyInfo(cv::Mat hom, std::vector<uchar> newStatus, std::vector<cv::DMatch> matches)
{
homography = hom;
status = newStatus;
inlier_matches = matches;
if(matches.size()>4) {
validHomography = true;
}
}

63 changes: 63 additions & 0 deletions WebARKit/WebARKitTrackers/WebARKitOpticalTracking/TrackedPoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* TrackedPoint.cpp
* WebARKit
*
* This file is part of WebARKit.
*
* WebARKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebARKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with WebARKit. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent modules, and to
* copy and distribute the resulting executable under terms of your choice,
* provided that you also meet, for each linked independent module, the terms and
* conditions of the license of that module. An independent module is a module
* which is neither derived from nor based on this library. If you modify this
* library, you may extend this exception to your version of the library, but you
* are not obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Copyright 2018 Realmax, Inc.
* Copyright 2015 Daqri, LLC.
* Copyright 2010-2015 ARToolworks, Inc.
* Copyright 2023 WebARKit
*
* Author(s): Philip Lamb, Daniel Bell, Walter Perdan
*
* This code was taken from artoolkitX https://github.com/artoolkitx/artoolkitx
* with small modifications to adapt to existing WebARKIt code.
*
*/

#include <WebARKitTrackers/WebARKitOpticalTracking/TrackedPoint.h>

bool TrackedPoint::IsTracking()
{
return tracking;
}

void TrackedPoint::SetTracking(bool newTracking)
{
tracking = newTracking;
}

bool TrackedPoint::IsSelected()
{
return selected;
}

void TrackedPoint::SetSelected(bool newSelected)
{
selected = newSelected;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*
* TrackingPointSelector.cpp
* WebARKit
*
* This file is part of WebARKit.
*
* WebARKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebARKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with WebARKit. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent modules, and to
* copy and distribute the resulting executable under terms of your choice,
* provided that you also meet, for each linked independent module, the terms and
* conditions of the license of that module. An independent module is a module
* which is neither derived from nor based on this library. If you modify this
* library, you may extend this exception to your version of the library, but you
* are not obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Copyright 2018 Realmax, Inc.
* Copyright 2015 Daqri, LLC.
* Copyright 2010-2015 ARToolworks, Inc.
* Copyright 2023 WebARKit
*
* Author(s): Philip Lamb, Daniel Bell, Walter Perdan
*
* This code was taken from artoolkitX https://github.com/artoolkitx/artoolkitx
* with small modifications to adapt to existing WebARKIt code.
*
*/

#include <WebARKitTrackers/WebARKitOpticalTracking/TrackingPointSelector.h>

TrackingPointSelector::TrackingPointSelector()
{

}

TrackingPointSelector::TrackingPointSelector(std::vector<cv::Point2f> pts, int width, int height, int markerTemplateWidth)
{
_pts = pts;
DistributeBins(width, height, markerTemplateWidth);
}

void TrackingPointSelector::DistributeBins(int width, int height, int markerTemplateWidth)
{
int numberOfBins = 10;

// Split width and height dimensions into 10 bins each, for total of 100 bins.
int totalXBins = width/numberOfBins;
int totalYBins = height/numberOfBins;
// Init empty bins.
for(int i=0; i<(numberOfBins * numberOfBins) ; i++) {
trackingPointBin.insert(std::pair<int, std::vector<TrackedPoint> >(i, std::vector<TrackedPoint>()));
}

// Iterate the points and add points to each bin.
for(int i=0, id=0; i<_pts.size(); i++) {
int bx = (int)_pts[i].x/totalXBins;
int by = (int)_pts[i].y/totalYBins;
int index = bx + (by * numberOfBins);

cv::Rect templateRoi = cv::Rect(_pts[i].x-markerTemplateWidth, _pts[i].y-markerTemplateWidth, markerTemplateWidth*2, markerTemplateWidth*2);
bool is_inside = (templateRoi & cv::Rect(0, 0, width, height)) == templateRoi; // templateRoi must not intersect image boundary.
if(is_inside) {
TrackedPoint newPt;
newPt.id = id;
newPt.pt = _pts[i];
newPt.pt3d = cv::Point3f(_pts[i].x, _pts[i].y, 0);
newPt.markerRoi = templateRoi;
trackingPointBin[index].push_back(newPt);
id++;
}
}
}

void TrackingPointSelector::SetHomography(cv::Mat newHomography)
{
homography = newHomography;
}

cv::Mat TrackingPointSelector::GetHomography()
{
return homography;
}

void TrackingPointSelector::UpdatePointStatus(std::vector<uchar> status)
{
int index = 0;
for(std::vector<TrackedPoint>::iterator it = _selectedPts.begin(); it != _selectedPts.end(); ++it) {
if(it->tracking) {
it->SetTracking((int)status[index++]);
}
}
}

void TrackingPointSelector::SelectPoints()
{
_selectedPts.clear();
for(auto &track : trackingPointBin) {
for(auto &trackPt : track.second) {
trackPt.SetSelected(false);
trackPt.SetTracking(false);
}
}
for(auto &track : trackingPointBin) {
if(track.second.size()>0) {
//Get a random idex for this track and choose that point from the points bin
int tIndex = rng.uniform(0, static_cast<int>(track.second.size()));
track.second[tIndex].SetSelected(true);
track.second[tIndex].SetTracking(true);
_selectedPts.push_back(track.second[tIndex]);
}
}
}

std::vector<cv::Point2f> TrackingPointSelector::GetSelectedFeatures()
{
std::vector<cv::Point2f> selectedPoints;
for(std::vector<TrackedPoint>::iterator it = _selectedPts.begin(); it != _selectedPts.end(); ++it) {
if(it->IsSelected()) {
selectedPoints.push_back(it->pt);
}
}
return selectedPoints;
}

std::vector<cv::Point2f> TrackingPointSelector::GetTrackedFeatures()
{
std::vector<cv::Point2f> selectedPoints;
for(std::vector<TrackedPoint>::iterator it = _selectedPts.begin(); it != _selectedPts.end(); ++it) {
if(it->IsTracking()) {
selectedPoints.push_back(it->pt);
}
}
return selectedPoints;
}

std::vector<cv::Point3f> TrackingPointSelector::GetSelectedFeatures3d()
{
std::vector<cv::Point3f> selectedPoints;
for(std::vector<TrackedPoint>::iterator it = _selectedPts.begin(); it != _selectedPts.end(); ++it) {
if(it->IsTracking()) {
selectedPoints.push_back(it->pt3d);
}
}
return selectedPoints;
}

std::vector<cv::Point2f> TrackingPointSelector::GetSelectedFeaturesWarped()
{
std::vector<cv::Point2f> warpedPoints;
std::vector<cv::Point2f> selectedPoints;
for(std::vector<TrackedPoint>::iterator it = _selectedPts.begin(); it != _selectedPts.end(); ++it) {
if(it->IsTracking()) {
selectedPoints.push_back(it->pt);
}
}
perspectiveTransform(selectedPoints, warpedPoints, homography);
return warpedPoints;
}

std::vector<cv::Point2f> TrackingPointSelector::GetAllFeatures()
{
std::vector<cv::Point2f> allBinnedPoints;
for(auto &track : trackingPointBin) {
for(auto &trackPt : track.second) {
allBinnedPoints.push_back(trackPt.pt);
}
}
return allBinnedPoints;
}

void TrackingPointSelector::CleanUp()
{
_selectedPts.clear();
_pts.clear();
trackingPointBin.clear();
homography.release();
}
Loading