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
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ class WebARKitTracker::WebARKitTrackerImpl {

float* getPoseMatrixGL() { return (float*)_patternTrackingInfo.trans; }

//float[3][4] getPoseMatrix3() { return _patternTrackingInfo.trans; }
//float (*getPoseMatrix3())[3][4] { return &_patternTrackingInfo.trans; }

cv::Mat getGLViewMatrix() { return _patternTrackingInfo.glViewMatrix; };

Expand All @@ -212,9 +210,6 @@ class WebARKitTracker::WebARKitTrackerImpl {
// std::cout << "Starting template match" << std::endl;
std::vector<cv::Point2f> finalTemplatePoints, finalTemplateMatchPoints;
// Get a handle on the corresponding points from current image and the marker
// std::vector<cv::Point2f> trackablePoints = _trackables[trackableId]._trackSelection.GetTrackedFeatures();
// std::vector<cv::Point2f> trackablePointsWarped =
// _trackables[trackableId]._trackSelection.GetTrackedFeaturesWarped();
std::vector<cv::Point2f> trackablePoints = _trackSelection.GetTrackedFeatures();
std::vector<cv::Point2f> trackablePointsWarped = _trackSelection.GetTrackedFeaturesWarped();
// Create an empty result image - May be able to pre-initialize this container
Expand All @@ -227,31 +222,23 @@ class WebARKitTracker::WebARKitTrackerImpl {

for (int j = 0; j < n; j++) {
auto pt = trackablePointsWarped[j];
// if (cv::pointPolygonTest(_trackables[trackableId]._bBoxTransformed, trackablePointsWarped[j], true) > 0)
// {
if (cv::pointPolygonTest(_bBoxTransformed, trackablePointsWarped[j], true) > 0) {
auto ptOrig = trackablePoints[j];

cv::Rect templateRoi = GetTemplateRoi(pt);
cv::Rect frameROI(0, 0, frame.cols, frame.rows);
if (IsRoiValidForFrame(frameROI, templateRoi)) {
// cv::Rect markerRoi(0, 0, _trackables[trackableId]._image.cols,
// _trackables[trackableId]._image.rows);
cv::Rect markerRoi(0, 0, _image.cols, _image.rows);

std::vector<cv::Point2f> vertexPoints = GetVerticesFromPoint(ptOrig);
std::vector<cv::Point2f> vertexPointsResults;
// perspectiveTransform(vertexPoints, vertexPointsResults,
// _trackables[trackableId]._trackSelection.GetHomography());
perspectiveTransform(vertexPoints, vertexPointsResults, _trackSelection.GetHomography());

cv::Rect srcBoundingBox = cv::boundingRect(cv::Mat(vertexPointsResults));

vertexPoints.clear();
vertexPoints = GetVerticesFromTopCorner(srcBoundingBox.x, srcBoundingBox.y, srcBoundingBox.width,
srcBoundingBox.height);
// perspectiveTransform(vertexPoints, vertexPointsResults,
// _trackables[trackableId]._trackSelection.GetHomography().inv());
perspectiveTransform(vertexPoints, vertexPointsResults, _trackSelection.GetHomography().inv());

std::vector<cv::Point2f> testVertexPoints = FloorVertexPoints(vertexPointsResults);
Expand All @@ -269,7 +256,6 @@ class WebARKitTracker::WebARKitTrackerImpl {

if (templateBoundingBox.area() > 0 && searchROI.area() > templateBoundingBox.area()) {
cv::Mat searchImage = frame(searchROI);
// cv::Mat templateImage = _trackables[trackableId]._image(templateBoundingBox);
cv::Mat templateImage = _image(templateBoundingBox);
cv::Mat warpedTemplate;

Expand Down Expand Up @@ -319,8 +305,6 @@ class WebARKitTracker::WebARKitTrackerImpl {
}
bool gotHomography = updateTrackableHomography(trackableId, finalTemplatePoints, finalTemplateMatchPoints);
if (!gotHomography) {
// _trackables[trackableId]._isTracking = false;
// _trackables[trackableId]._isDetected = false;
_isTracking = false;
_isDetected = false;
// WebARKitLib#46: template matching is the appearance check -- if it fails
Expand Down Expand Up @@ -501,7 +485,6 @@ class WebARKitTracker::WebARKitTrackerImpl {
int maxMatches = 0;
int bestMatchIndex = -1;
std::vector<cv::KeyPoint> finalMatched1, finalMatched2;
// for (int i = 0; i < _trackables.size(); i++) {
if (!_isDetected) {
std::vector<std::vector<cv::DMatch>> matches = getMatches(newFrameDescriptors);
numMatches = matches.size();
Expand Down Expand Up @@ -549,24 +532,17 @@ class WebARKitTracker::WebARKitTrackerImpl {
getHomographyInliers(Points(finalMatched2), Points(finalMatched1));
if (homoInfo.validHomography) {
// std::cout << "New marker detected" << std::endl;
//_trackables[bestMatchIndex]._isDetected = true;
_isDetected = true;
// Since we've just detected the marker, make sure next invocation of
// GetInitialFeatures() for this marker makes a new selection.
//_trackables[bestMatchIndex]._trackSelection.ResetSelection();
_trackSelection.ResetSelection();
//_trackables[bestMatchIndex]._trackSelection.SetHomography(homoInfo.homography);
_trackSelection.SetHomography(homoInfo.homography);

// Use the homography to form the initial estimate of the bounding box.
// This will be refined by the optical flow pass.
// perspectiveTransform(_trackables[bestMatchIndex]._bBox, _trackables[bestMatchIndex]._bBoxTransformed,
// homoInfo.homography);
perspectiveTransform(_bBox, _bBoxTransformed, homoInfo.homography);
if (_trackVizActive) {
for (int i = 0; i < 4; i++) {
// _trackViz.bounds[i][0] = _trackables[bestMatchIndex]._bBoxTransformed[i].x;
// _trackViz.bounds[i][1] = _trackables[bestMatchIndex]._bBoxTransformed[i].y;
_trackViz.bounds[i][0] = _bBoxTransformed[i].x;
_trackViz.bounds[i][1] = _bBoxTransformed[i].y;
}
Expand Down Expand Up @@ -632,14 +608,11 @@ class WebARKitTracker::WebARKitTrackerImpl {
perspectiveTransform(_bBox, _bBoxTransformed, homoInfo.homography);
if (_trackVizActive) {
for (int i = 0; i < 4; i++) {
// _trackViz.bounds[i][0] = _trackables[trackableId]._bBoxTransformed[i].x;
// _trackViz.bounds[i][1] = _trackables[trackableId]._bBoxTransformed[i].y;
_trackViz.bounds[i][0] = _bBoxTransformed[i].x;
_trackViz.bounds[i][1] = _bBoxTransformed[i].y;
}
}
if (_frameCount > 1) {
// _trackables[trackableId]._trackSelection.ResetSelection();
_trackSelection.ResetSelection();
}
return true;
Expand Down Expand Up @@ -896,8 +869,6 @@ cv::Mat WebARKitTracker::getPoseMatrixCV() { return _trackerImpl->getPoseMatrixC

float* WebARKitTracker::getPoseMatrixGL() { return _trackerImpl->getPoseMatrixGL(); }

//float[3][4] WebARKitTracker::getPoseMatrix3() { return _trackerImpl->getPoseMatrix3(); }
//float (*WebARKitTracker::getPoseMatrix3())[3][4]) { return &_trackerImpl->getPoseMatrix3(); }

cv::Mat WebARKitTracker::getGLViewMatrix() { return _trackerImpl->getGLViewMatrix(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class WebARKitTracker {

float* getPoseMatrixGL();

//float (*WebARKitTracker::getPoseMatrix3()[3][4]);

cv::Mat getGLViewMatrix();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,6 @@ static homography::WebARKitHomographyInfo getHomographyInliers(std::vector<cv::P
return homography::WebARKitHomographyInfo(homography, status, inlier_matches);
}

/*static auto im_gray(uchar* data, size_t cols, size_t rows) {
uint32_t idx;
uchar gray[rows][cols];
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
idx = (i * cols * 4) + j * 4;

// rgba to rgb
uchar r = data[idx];
uchar g = data[idx + 1];
uchar b = data[idx + 2];
// uchar a = data[idx + 3];

// turn frame image to gray scale
gray[i][j] = (0.30 * r) + (0.59 * g) + (0.11 * b);
}
}

return cv::Mat(rows, cols, CV_8UC1, gray);
}*/

static auto convert2Grayscale(cv::Mat& refData, size_t refCols, size_t refRows, ColorSpace colorSpace) {
cv::Mat refGray;

Expand Down
2 changes: 0 additions & 2 deletions WebARKit/include/WebARKitManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class WebARKitManager {

bool initTracker(uchar* refData, size_t refCols, size_t refRows, ColorSpace colorSpace);

bool update();

void setLogLevel(int logLevel);

bool shutdown();
Expand Down
Loading