热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

特征检测之特征提取(Detect)

特征检测之特征提取(Detect)DetectkeypointsinimageusingthetraditionalShi-Thomasidetecto

特征检测之特征提取(Detect)

在这里插入图片描述

// Detect keypoints in image using the traditional Shi-Thomasi detector
void detKeypointsShiTomasi(vector &keypoints, cv::Mat &img, bool bVis)
{// compute detector parameters based on image sizeint blockSize &#61; 4; // size of an average block for computing a derivative covariation matrix over each pixel neighborhooddouble maxOverlap &#61; 0.0; // max. permissible overlap between two features in %double minDistance &#61; (1.0 - maxOverlap) * blockSize;int maxCorners &#61; img.rows * img.cols / max(1.0, minDistance); // max. num. of keypointsdouble qualityLevel &#61; 0.01; // minimal accepted quality of image cornersdouble k &#61; 0.04;// Apply corner detectiondouble t &#61; (double)cv::getTickCount();vector corners;cv::goodFeaturesToTrack(img, corners, maxCorners, qualityLevel, minDistance, cv::Mat(), blockSize, false, k);// add corners to result vectorfor (auto it &#61; corners.begin(); it !&#61; corners.end(); &#43;&#43;it){cv::KeyPoint newKeyPoint;newKeyPoint.pt &#61; cv::Point2f((*it).x, (*it).y);newKeyPoint.size &#61; blockSize;keypoints.push_back(newKeyPoint);}t &#61; ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout <<"Shi-Tomasi detection with n&#61;" <}//FAST, BRISK, ORB, AKAZE, SIFT
void detKeypointsModern(std::vector &keypoints, cv::Mat &img, std::string detectorType, bool bVis)
{string windowName;if (detectorType.compare("FAST") &#61;&#61; 0){int threshold &#61; 30;bool bNMS &#61; true;cv::FastFeatureDetector::DetectorType type &#61; cv::FastFeatureDetector::TYPE_9_16; // TYPE_9_16, TYPE_7_12, TYPE_5_8cv::Ptr detector &#61; cv::FastFeatureDetector::create(threshold, bNMS, type);double t &#61; (double)cv::getTickCount();detector->detect(img, keypoints);t &#61; ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout <<"FAST detection with n&#61; " < detector &#61; cv::BRISK::create();double t &#61; (double)cv::getTickCount();detector->detect(img, keypoints);t &#61; ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout <<"BRISK detection with n&#61; " < detector &#61; cv::ORB::create();double t &#61; (double)cv::getTickCount();detector->detect(img, keypoints);t &#61; ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout <<"ORB detection with n&#61; " < detector &#61; cv::AKAZE::create();double t &#61; (double)cv::getTickCount();detector->detect(img, keypoints);t &#61; ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout <<"AKAZE detection with n&#61; " < detector &#61; cv::xfeatures2d::SIFT::create();double t &#61; (double)cv::getTickCount();detector->detect(img, keypoints);t &#61; ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout <<"SIFT detection with n&#61; " <}// Detect keypoints in image using the traditional Harris detector
void detKeypointsHarris(std::vector &keypoints, cv::Mat &img, bool bVis)
{// Detector parametersint blockSize &#61; 2; // for every pixel, a blockSize × blockSize neighborhood is consideredint apertureSize &#61; 3; // aperture parameter for Sobel operator (must be odd)int minResponse &#61; 100; // minimum value for a corner in the 8bit scaled response matrixdouble k &#61; 0.04; // Harris parameter (see equation for details)// Detect Harris corners and normalize outputdouble t &#61; (double)cv::getTickCount();cv::Mat dst, dst_norm, dst_norm_scaled;dst &#61; cv::Mat::zeros(img.size(), CV_32FC1);cv::cornerHarris(img, dst, blockSize, apertureSize, k, cv::BORDER_DEFAULT);cv::normalize(dst, dst_norm, 0, 255, cv::NORM_MINMAX, CV_32FC1, cv::Mat());cv::convertScaleAbs(dst_norm, dst_norm_scaled);double maxOverlap &#61; 0.0; // max. permissible overlap between two features in %, used during non-maxima suppressionfor (size_t j &#61; 0; j (j, i);if (response > minResponse){ // only store points above a thresholdcv::KeyPoint newKeyPoint;newKeyPoint.pt &#61; cv::Point2f(i, j);newKeyPoint.size &#61; 2 * apertureSize;newKeyPoint.response &#61; response;// perform non-maximum suppression (NMS) in local neighbourhood around new key pointbool bOverlap &#61; false;for (auto it &#61; keypoints.begin(); it !&#61; keypoints.end(); &#43;&#43;it){double kptOverlap &#61; cv::KeyPoint::overlap(newKeyPoint, *it);if (kptOverlap > maxOverlap){bOverlap &#61; true;if (newKeyPoint.response > (*it).response){ // if overlap is >t AND response is higher for new kpt*it &#61; newKeyPoint; // replace old key point with new onebreak; // quit loop over keypoints}}}if (!bOverlap){ // only add new key point if no overlap has been found in previous NMSkeypoints.push_back(newKeyPoint); // store new keypoint in dynamic list}}} // eof loop over cols} // eof loop over rowst &#61; ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout <<"Harris detection with n&#61;" <


推荐阅读
author-avatar
命运2502901041_350
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有