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 @@ -170,6 +170,13 @@ std::vector<cv::Point2f> TrackingPointSelector::GetTrackedFeaturesWarped()
{
std::vector<cv::Point2f> selectedPoints = GetTrackedFeatures();
std::vector<cv::Point2f> warpedPoints;
// cv::perspectiveTransform asserts on an empty input (and requires a valid
// 3x3 homography). This happens when a marker is detected on the very first
// frame, before the tracked-point selection has been populated. Return an
// empty result instead of throwing.
if (selectedPoints.empty() || _homography.empty()) {
return warpedPoints;
}
perspectiveTransform(selectedPoints, warpedPoints, _homography);
return warpedPoints;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,20 @@ class WebARKitTracker::WebARKitTrackerImpl {
cv::Mat _pose;
std::vector<cv::Point2f> imgPoints = _trackSelection.GetTrackedFeaturesWarped();
std::vector<cv::Point3f> objPoints = _trackSelection.GetTrackedFeatures3d();
_patternTrackingInfo.cameraPoseFromPoints(_pose, objPoints, imgPoints, m_camMatrix, m_distortionCoeff);
// _patternTrackingInfo.computePose(_pattern.points3d, warpedCorners, m_camMatrix, m_distortionCoeff);
_patternTrackingInfo.getTrackablePose(_pose);
_patternTrackingInfo.updateTrackable();
_patternTrackingInfo.computeGLviewMatrix(_pose);
fill_output(m_H);
WEBARKIT_LOGi("Marker tracked ! Num. matches : %d\n", numMatches);
// 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
// branch that calls GetInitialFeatures() is gated on _frameCount > 0),
// leaving these empty. Skip pose estimation in that case.
if (imgPoints.size() >= 4 && imgPoints.size() == objPoints.size()) {
_patternTrackingInfo.cameraPoseFromPoints(_pose, objPoints, imgPoints, m_camMatrix, m_distortionCoeff);
// _patternTrackingInfo.computePose(_pattern.points3d, warpedCorners, m_camMatrix, m_distortionCoeff);
_patternTrackingInfo.getTrackablePose(_pose);
_patternTrackingInfo.updateTrackable();
_patternTrackingInfo.computeGLviewMatrix(_pose);
fill_output(m_H);
WEBARKIT_LOGi("Marker tracked ! Num. matches : %d\n", numMatches);
}
}

swapImagePyramid();
Expand Down