BitmapToolkit Scol plugin
|
ArFeaturedMarker.cpp
Go to the documentation of this file.
40 symTestParallel(const std::vector<std::vector<cv::DMatch> >& _matches1, const std::vector<std::vector<cv::DMatch> >& _matches2, std::vector<std::vector<cv::DMatch> > &_omatchVec)
52 for (std::vector<std::vector<cv::DMatch> >::const_iterator matchIterator1 = (matches1.begin() + start); matchIterator1 != (matches1.begin() + end); ++matchIterator1)
73 omatchVec[cv::getThreadNum()].push_back(cv::DMatch((*matchIterator1)[0].queryIdx, (*matchIterator1)[0].trainIdx, (*matchIterator1)[0].distance));
144 std::vector<cv::KeyPoint>& keypoints_frame, const cv::Mat& descriptors_model, const cv::Mat& mask)
155 matcher_->knnMatch(descriptors_frame, descriptors_model, matches12, 2); // return 2 nearest neighbours
193bool RobustMatcher::addTrainData(const cv::Mat& frame, std::vector<cv::KeyPoint> &marker_keypoints)
235ArFeaturedMarker::ArFeaturedMarker(std::string filePath, unsigned int nid, float size, unsigned int maxFeatures) : ArMarker(nid, size, ArMarker::AR_FFT_MARKER)
288ArFeaturedMarker::ArFeaturedMarker(cv::Mat tpl, unsigned int nid, float size, unsigned int maxFeatures) : ArMarker(nid, size, ArMarker::AR_FFT_MARKER)
299ArFeaturedMarker::ArFeaturedMarker(unsigned int nid, float size) : ArMarker(nid, size, ArMarker::AR_FACE_MARKER)
354 // resize the marker for bigger detection and this avoid an infinite loop on pyramid detection on small pictures
429 m_pcorners.push_back(cv::Point2f(static_cast<float>(m_image.cols), static_cast<float>(m_image.rows)));
433 cv::Ptr<cv::flann::IndexParams> indexParams = cv::makePtr<cv::flann::LshIndexParams>(6, 12, 1); // instantiate LSH index parameters
434 cv::Ptr<cv::flann::SearchParams> searchParams = cv::makePtr<cv::flann::SearchParams>(50); // instantiate flann search parameters
469 cv::Ptr<cv::AKAZE> sdetector = cv::AKAZE::create(cv::AKAZE::DESCRIPTOR_MLDB, 0, 3, threshold, 32, 4, cv::KAZE::DIFF_PM_G2);
483 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
487 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
491 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
495 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
499 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
503 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
507 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
511 cv::warpPerspective(warp, warped, hmat, cv::Size(warp.cols, warp.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
522bool ArFeaturedMarker::GetPointsFromMatches(const std::vector<cv::KeyPoint> &querykeypoints, const std::vector<cv::KeyPoint> &trainKeypoints, std::vector<cv::DMatch> matches, std::vector<cv::Point2f> &trainPoints, std::vector<cv::Point2f> &framePoints)
538bool ArFeaturedMarker::GetHomography(std::vector<cv::Point2f> &trainPoints, std::vector<cv::Point2f> &framePoints, cv::Mat &HMatrix)
543 HMatrix = findHomography(trainPoints, framePoints, cv::FM_RANSAC, m_HomographyThreshold);// , status);
617bool ArFeaturedMarker::detectMotionFlow(cv::Mat &frame, cv::Mat &color, const std::vector<cv::Point2f> &trainPoints, const std::vector<cv::Point2f> &framePoints, std::vector<cv::Point2f> >rainPoints, std::vector<cv::Point2f> &gframePoints)
635 cv::calcOpticalFlowPyrLK(m_prevPyr, m_nextPyr, framePoints, newFramePoints, status, err, winSize, 8, termcrit, cv::OPTFLOW_FARNEBACK_GAUSSIAN, 0.001f);
679 if (m_lastFrameSize.width != frame.cols || m_lastFrameSize.height != frame.rows || m_registerNextFrame)
693 if (m_registerNextFrame && camsize.width != 0 && camsize.height != 0 && m_cropSize.width > 1 && m_cropSize.height > 1)
696 cv::Point2f scale = cv::Point2f((float)frame.cols / (float)camsize.width, (float)frame.rows / (float)camsize.height);
706 cv::Mat crop(frame, cv::Rect(m_cropPos.x, m_cropPos.y, m_cropSize.width, m_cropSize.height)); // NOTE: this will only give you a reference to the ROI of the original data
740 bool motion = detectMotionFlow(frame, color, m_prevTrainPoints, m_prevFramePoints, gTrainPoints, gFramePoints);
764 if ((m_dmask.rows == 0) || (m_dmask.cols == 0) || m_dmask.empty() || (m_dmask.rows != frame.rows) || m_dmask.cols != frame.cols)
779 if ((m_lastFound = GetPointsFromMatches(keypoints, m_trainKeypoints, matches, trainPoints, framePoints)))
792 if ((m_lastFound = GetHomography(trainPoints, framePoints, HMatrix)) && (m_lastFound = GetCorners(HMatrix)))
798 detectMotionFlow(frame, color, m_prevTrainPoints, m_prevFramePoints, gFramePoints, gTrainPoints);
802 cv::warpPerspective(color, m_warped, HMatrix, cv::Size(m_image.cols, m_image.rows), cv::WARP_INVERSE_MAP | cv::INTER_CUBIC);
838void ArFeaturedMarker::calculateFeaturedExtrinsics(float markerSizeMeters, aruco::CameraParameters& camParams, bool setYPerperdicular)
841 throw cv::Exception(9004, "!isValid(): invalid camera parameters. It is not possible to calculate extrinsics", "calculateExtrinsics", __FILE__, __LINE__);
844 throw cv::Exception(9004, "!isValid(): invalid marker. It is not possible to calculate extrinsics", "calculateExtrinsics", __FILE__, __LINE__);
846 throw cv::Exception(9004, "markerSize<=0: invalid markerSize", "calculateExtrinsics", __FILE__, __LINE__);
879 cv::Point2f scale = cv::Point2f((float)m_lastFrameSize.width / (float)camParams.CamSize.width, (float)m_lastFrameSize.height / (float)camParams.CamSize.height);
903void ArFeaturedMarker::Update(cv::Mat frame, cv::Mat color, aruco::CameraParameters& camparam, bool reverse)
907 //bool found = (m_visible && m_fmarker->detectMotionFlow(m_lastFrame)) ? true : m_fmarker->detectFeatured(m_lastFrame);
935 pixelPosition.z = sqrt(pow(((*this).at(1).x - (*this).at(0).x), 2) + pow(((*this).at(1).y - (*this).at(0).y), 2));
936 pixelPosition.z += sqrt(pow(((*this).at(2).x - (*this).at(1).x), 2) + pow(((*this).at(2).y - (*this).at(1).y), 2));
937 pixelPosition.z += sqrt(pow(((*this).at(3).x - (*this).at(2).x), 2) + pow(((*this).at(3).y - (*this).at(2).y), 2));
938 pixelPosition.z += sqrt(pow(((*this).at(0).x - (*this).at(3).x), 2) + pow(((*this).at(0).y - (*this).at(3).y), 2));
944 //cv::circle(image, Point(pixelPosition.x, pixelPosition.y),pixelPosition.z/2,cv::Scalar(255,0,255));
948 SetPosition(Vector3(static_cast<float>(reverse ? -modelview_matrix[12] : modelview_matrix[12]), static_cast<float>(modelview_matrix[13]), static_cast<float>(modelview_matrix[14])));
void Update(cv::Mat frame, cv::Mat color, aruco::CameraParameters &camparam, bool reverse)
Definition ArFeaturedMarker.cpp:903
void calculateFeaturedExtrinsics(float markerSize, aruco::CameraParameters &camParams, bool setYPerpendicular=true)
Definition ArFeaturedMarker.cpp:838
void RegisterNextFrame(cv::Point point, cv::Size size)
Definition ArFeaturedMarker.cpp:442
bool detectFeatured(cv::Mat &frame, cv::Mat &color, cv::Size camsize)
Definition ArFeaturedMarker.cpp:677
bool GetWarpedMarker(cv::Mat &image)
Definition ArFeaturedMarker.cpp:665
void SetTrackedImage(cv::Mat tpl)
Definition ArFeaturedMarker.cpp:307
std::vector< cv::Point2f > m_prevFramePoints
Definition ArFeaturedMarker.h:109
ArFeaturedMarker(std::string filePath, unsigned int nid, float size, unsigned int maxFeatures=600)
Definition ArFeaturedMarker.cpp:235
Definition ArMarker.h:38
static BtQuaternion FromRotationMatrix(double rotMatrix[16], bool reverseX=false, bool reverseY=true)
Definition Prerequisites.h:396
std::vector< cv::Point2f > GetFilteredPoints()
Definition Prerequisites.h:722
void Update(std::vector< cv::Point2f > points)
Definition Prerequisites.h:597
void Init(float fSmoothing=0.25f, float fCorrection=0.25f, float fPrediction=0.25f, float fJitterRadius=0.03f, float fMaxDeviationRadius=0.05f)
Definition Prerequisites.h:566
Definition ArFeaturedMarker.h:43
void setDescriptorMatcher(const cv::Ptr< cv::DescriptorMatcher > &match)
Definition ArFeaturedMarker.h:55
void setFeatureDetector(const cv::Ptr< cv::FeatureDetector > &detect)
Definition ArFeaturedMarker.h:49
bool addTrainData(const cv::Mat &frame, std::vector< cv::KeyPoint > &marker_keypoints)
Definition ArFeaturedMarker.cpp:193
void fastRobustMatch(const cv::Mat &frame, std::vector< cv::DMatch > &good_matches, std::vector< cv::KeyPoint > &keypoints_frame, const cv::Mat &mask)
Definition ArFeaturedMarker.cpp:170
int ratioTest(std::vector< std::vector< cv::DMatch > > &matches)
Definition ArFeaturedMarker.cpp:102
void setTrainFeatureDetector(const cv::Ptr< cv::FeatureDetector > &detect)
Definition ArFeaturedMarker.h:52
void robustMatch(const cv::Mat &frame, std::vector< cv::DMatch > &good_matches, std::vector< cv::KeyPoint > &keypoints_frame, const cv::Mat &descriptors_model, const cv::Mat &mask)
Definition ArFeaturedMarker.cpp:143
void symmetryTest(const std::vector< std::vector< cv::DMatch > > &matches1, const std::vector< std::vector< cv::DMatch > > &matches2, std::vector< cv::DMatch > &symMatches)
Definition ArFeaturedMarker.cpp:127
Definition Prerequisites.h:177
Generated by 1.9.8