当前位置: 首页>>代码示例>>C++>>正文


C++ Matches::scenePts方法代码示例

本文整理汇总了C++中Matches::scenePts方法的典型用法代码示例。如果您正苦于以下问题:C++ Matches::scenePts方法的具体用法?C++ Matches::scenePts怎么用?C++ Matches::scenePts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matches的用法示例。


在下文中一共展示了Matches::scenePts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
   cv::VideoCapture cap("../data/guitar_scene.mp4");
   if(!cap.isOpened()) {
      cerr << "Camera/Video was not opened\n";
      return 1;
   }

   //SystemAlgorithms algorithms(new SIFTDetector(500), new SIFTExtractor, new BruteForceMatcher(cv::NORM_L2), new LucasKanadeAlgorithm);
   SystemAlgorithms algorithms = SystemAlgorithms::Create(false, true);

   HybridTracker tracker(algorithms);

   Marker target = tracker.Registry(PreMarker("../data/guitar_object.jpg", nullptr));
   Size2i targetSize = target.GetSize();

   vector<cv::Point2f> targetCorner(4);
   targetCorner[0] = cv::Point2f(0.0, 0.0);
   targetCorner[3] = cv::Point2f(0.0, targetSize.height);
   targetCorner[2] = cv::Point2f(targetSize.width, targetSize.height);
   targetCorner[1] = cv::Point2f(targetSize.width, 0.0);

   uint numFrames = 0;
   double time = (double) cv::getTickCount();

   Frame frame;
   Matches matches;

   while(true) {
      cap >> frame.image;

      if(frame.image.empty() and numFrames == 0) continue;
      if(frame.image.empty()) break;

      numFrames++;

      tracker.Update(frame);
      matches = tracker.Find(target, frame);

      if(matches.size() > 20) target.SetLost(false);
      else target.SetLost(true);

      if(matches.size() >= 4) {
         vector<Point2f> corners;
         Mat homography = cv::findHomography(matches.targetPts(), matches.scenePts(), cv::RANSAC, 4);
         cv::perspectiveTransform(targetCorner, corners, homography);

         if(!corners.empty()) {
            cv::line(frame.image, corners[0], corners[1], cv::Scalar(0, 255, 0), 4);
            cv::line(frame.image, corners[1], corners[2], cv::Scalar(0, 255, 0), 4);
            cv::line(frame.image, corners[2], corners[3], cv::Scalar(0, 255, 0), 4);
            cv::line(frame.image, corners[3], corners[0], cv::Scalar(0, 255, 0), 4);
         }
      }

      for(auto p : matches.scenePts()) {
         cv::circle(frame.image, p, 3, cv::Scalar(0, 255, 0), 1);
      }

      cv::imshow("Tracker Test", frame.image);
      char key = cv::waitKey(1);
      if(key == 0x1B) // ESC
         break;
   }

   time = (double)(cv::getTickCount() - time) / cv::getTickFrequency();
   cout << (numFrames/time) << " fps\n";

   return 0;
}
开发者ID:AVRGroup,项目名称:Markerless-AVRLib,代码行数:69,代码来源:main.cpp


注:本文中的Matches::scenePts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。