opencv-建立自己的角點檢測
轉自:http://blog.csdn.net/tianzhaixing/article/details/8988731
本文運用opencv函式cornerEigenValsAndVecs來查詢eigenvalues和eigenvectors判斷畫素點是否為角點。
運用opencv函式cornerMinEigenVal查詢檢測角點的最小值。
- /**
- * @function cornerDetector_Demo.cpp
- * @brief Demo code for detecting corners using OpenCV built-in functions
- * @author OpenCV team
- */
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace cv;
- using namespace std;
- /// Global variables
- Mat src, src_gray;
- Mat myHarris_dst; Mat myHarris_copy; Mat Mc;
- Mat myShiTomasi_dst; Mat myShiTomasi_copy;
- int myShiTomasi_qualityLevel = 50;
- int myHarris_qualityLevel = 50;
- int max_qualityLevel = 100;
- double myHarris_minVal; double myHarris_maxVal;
- double myShiTomasi_minVal; double myShiTomasi_maxVal;
- RNG rng(12345);
- const char* myHarris_window = "My Harris corner detector";
- const char* myShiTomasi_window = "My Shi Tomasi corner detector";
- /// Function headers
- void myShiTomasi_function( int, void* );
- void myHarris_function( int, void* );
- /**
- * @function main
- */
- int main( int, char** argv )
- {
- /// Load source image and convert it to gray
- src = imread( argv[1], 1 );
- cvtColor( src, src_gray, COLOR_BGR2GRAY );
- /// Set some parameters
- int blockSize = 3; int apertureSize = 3;
- /// My Harris matrix -- Using cornerEigenValsAndVecs
- myHarris_dst = Mat::zeros( src_gray.size(), CV_32FC(6) );
- Mc = Mat::zeros( src_gray.size(), CV_32FC1 );
- cornerEigenValsAndVecs( src_gray, myHarris_dst, blockSize, apertureSize, BORDER_DEFAULT );
- /* calculate Mc */
- for( int j = 0; j < src_gray.rows; j++ )
- { for( int i = 0; i < src_gray.cols; i++ )
- {
- float lambda_1 = myHarris_dst.at<Vec6f>(j, i)[0];
- float lambda_2 = myHarris_dst.at<Vec6f>(j, i)[1];
- Mc.at<float>(j,i) = lambda_1*lambda_2 - 0.04f*pow( ( lambda_1 + lambda_2 ), 2 );
- }
- }
- minMaxLoc( Mc, &myHarris_minVal, &myHarris_maxVal, 0, 0, Mat() );
- /* Create Window and Trackbar */
- namedWindow( myHarris_window, WINDOW_AUTOSIZE );
- createTrackbar( " Quality Level:", myHarris_window, &myHarris_qualityLevel, max_qualityLevel, myHarris_function );
- myHarris_function( 0, 0 );
- /// My Shi-Tomasi -- Using cornerMinEigenVal
- myShiTomasi_dst = Mat::zeros( src_gray.size(), CV_32FC1 );
- cornerMinEigenVal( src_gray, myShiTomasi_dst, blockSize, apertureSize, BORDER_DEFAULT );
- minMaxLoc( myShiTomasi_dst, &myShiTomasi_minVal, &myShiTomasi_maxVal, 0, 0, Mat() );
- /* Create Window and Trackbar */
- namedWindow( myShiTomasi_window, WINDOW_AUTOSIZE );
- createTrackbar( " Quality Level:", myShiTomasi_window, &myShiTomasi_qualityLevel, max_qualityLevel, myShiTomasi_function );
- myShiTomasi_function( 0, 0 );
- waitKey(0);
- return(0);
- }
- /**
- * @function myShiTomasi_function
- */
- void myShiTomasi_function( int, void* )
- {
- myShiTomasi_copy = src.clone();
- if( myShiTomasi_qualityLevel < 1 ) { myShiTomasi_qualityLevel = 1; }
- for( int j = 0; j < src_gray.rows; j++ )
- { for( int i = 0; i < src_gray.cols; i++ )
- {
- if( myShiTomasi_dst.at<float>(j,i) > myShiTomasi_minVal + ( myShiTomasi_maxVal - myShiTomasi_minVal )*myShiTomasi_qualityLevel/max_qualityLevel )
- { circle( myShiTomasi_copy, Point(i,j), 4, Scalar( rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 ); }
- }
- }
- imshow( myShiTomasi_window, myShiTomasi_copy );
- }
- /**
- * @function myHarris_function
- */
- void myHarris_function( int, void* )
- {
- myHarris_copy = src.clone();
- if( myHarris_qualityLevel < 1 ) { myHarris_qualityLevel = 1; }
- for( int j = 0; j < src_gray.rows; j++ )
- { for( int i = 0; i < src_gray.cols; i++ )
- {
- if( Mc.at<float>(j,i) > myHarris_minVal + ( myHarris_maxVal - myHarris_minVal )*myHarris_qualityLevel/max_qualityLevel )
- { circle( myHarris_copy, Point(i,j), 4, Scalar( rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 ); }
- }
- }
- imshow( myHarris_window, myHarris_copy );
- }
/**
* @function cornerDetector_Demo.cpp
* @brief Demo code for detecting corners using OpenCV built-in functions
* @author OpenCV team
*/
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
/// Global variables
Mat src, src_gray;
Mat myHarris_dst; Mat myHarris_copy; Mat Mc;
Mat myShiTomasi_dst; Mat myShiTomasi_copy;
int myShiTomasi_qualityLevel = 50;
int myHarris_qualityLevel = 50;
int max_qualityLevel = 100;
double myHarris_minVal; double myHarris_maxVal;
double myShiTomasi_minVal; double myShiTomasi_maxVal;
RNG rng(12345);
const char* myHarris_window = "My Harris corner detector";
const char* myShiTomasi_window = "My Shi Tomasi corner detector";
/// Function headers
void myShiTomasi_function( int, void* );
void myHarris_function( int, void* );
/**
* @function main
*/
int main( int, char** argv )
{
/// Load source image and convert it to gray
src = imread( argv[1], 1 );
cvtColor( src, src_gray, COLOR_BGR2GRAY );
/// Set some parameters
int blockSize = 3; int apertureSize = 3;
/// My Harris matrix -- Using cornerEigenValsAndVecs
myHarris_dst = Mat::zeros( src_gray.size(), CV_32FC(6) );
Mc = Mat::zeros( src_gray.size(), CV_32FC1 );
cornerEigenValsAndVecs( src_gray, myHarris_dst, blockSize, apertureSize, BORDER_DEFAULT );
/* calculate Mc */
for( int j = 0; j < src_gray.rows; j++ )
{ for( int i = 0; i < src_gray.cols; i++ )
{
float lambda_1 = myHarris_dst.at<Vec6f>(j, i)[0];
float lambda_2 = myHarris_dst.at<Vec6f>(j, i)[1];
Mc.at<float>(j,i) = lambda_1*lambda_2 - 0.04f*pow( ( lambda_1 + lambda_2 ), 2 );
}
}
minMaxLoc( Mc, &myHarris_minVal, &myHarris_maxVal, 0, 0, Mat() );
/* Create Window and Trackbar */
namedWindow( myHarris_window, WINDOW_AUTOSIZE );
createTrackbar( " Quality Level:", myHarris_window, &myHarris_qualityLevel, max_qualityLevel, myHarris_function );
myHarris_function( 0, 0 );
/// My Shi-Tomasi -- Using cornerMinEigenVal
myShiTomasi_dst = Mat::zeros( src_gray.size(), CV_32FC1 );
cornerMinEigenVal( src_gray, myShiTomasi_dst, blockSize, apertureSize, BORDER_DEFAULT );
minMaxLoc( myShiTomasi_dst, &myShiTomasi_minVal, &myShiTomasi_maxVal, 0, 0, Mat() );
/* Create Window and Trackbar */
namedWindow( myShiTomasi_window, WINDOW_AUTOSIZE );
createTrackbar( " Quality Level:", myShiTomasi_window, &myShiTomasi_qualityLevel, max_qualityLevel, myShiTomasi_function );
myShiTomasi_function( 0, 0 );
waitKey(0);
return(0);
}
/**
* @function myShiTomasi_function
*/
void myShiTomasi_function( int, void* )
{
myShiTomasi_copy = src.clone();
if( myShiTomasi_qualityLevel < 1 ) { myShiTomasi_qualityLevel = 1; }
for( int j = 0; j < src_gray.rows; j++ )
{ for( int i = 0; i < src_gray.cols; i++ )
{
if( myShiTomasi_dst.at<float>(j,i) > myShiTomasi_minVal + ( myShiTomasi_maxVal - myShiTomasi_minVal )*myShiTomasi_qualityLevel/max_qualityLevel )
{ circle( myShiTomasi_copy, Point(i,j), 4, Scalar( rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 ); }
}
}
imshow( myShiTomasi_window, myShiTomasi_copy );
}
/**
* @function myHarris_function
*/
void myHarris_function( int, void* )
{
myHarris_copy = src.clone();
if( myHarris_qualityLevel < 1 ) { myHarris_qualityLevel = 1; }
for( int j = 0; j < src_gray.rows; j++ )
{ for( int i = 0; i < src_gray.cols; i++ )
{
if( Mc.at<float>(j,i) > myHarris_minVal + ( myHarris_maxVal - myHarris_minVal )*myHarris_qualityLevel/max_qualityLevel )
{ circle( myHarris_copy, Point(i,j), 4, Scalar( rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 ); }
}
}
imshow( myHarris_window, myHarris_copy );
}
相關文章
- 【OpenCV】角點檢測:Harris角點及Shi-Tomasi角點檢測OpenCV
- Harris角點檢測
- 2.Harris角點檢測
- Fast角點檢測演算法AST演算法
- OpenCV探索之路(十五):角點檢測OpenCV
- openCV - 角點檢測快速演算法 FASTOpenCV演算法AST
- OpenCV學習筆記-Harris角點檢測OpenCV筆記
- Shi-Tomas檢測和SHIF角點匹配
- [Computer Vision]Harris角點檢測的詳細推導
- Python計算機視覺——Harris角點檢測Python計算機視覺
- OpenCV計算機視覺學習(13)——影像特徵點檢測(Harris角點檢測,sift演算法)OpenCV計算機視覺特徵演算法
- 【火爐煉AI】機器學習048-Harris檢測影像角點AI機器學習
- 自己編寫的(測試點總結)
- 目標檢測---教你利用yolov5訓練自己的目標檢測模型YOLO模型
- 筆記-圓角四種方法的對比以及效能檢測筆記
- 如何部署自己的SSD檢測模型到AndroidTFLite上模型Android
- opencv關鍵點檢測OpenCV
- opencv-圖片馬賽克處理OpenCV
- 自動化測試新視角:以SaaS模式檢測內網安全模式內網
- github 建立自己的主頁Github
- Github 建立自己的專案Github
- 建立了自己的部落格
- 【TUNE_ORACLE】Oracle檢查點(五)建立並利用Statspack定位檢查點故障Oracle
- Opencv中goodFeaturesToTrack函式(Harris角點、Shi-Tomasi角點檢測)運算元速度的進一步最佳化(1920*1080測試圖11ms處理完成)。OpenCVGoREST函式
- JVM視角看物件建立JVM物件
- iOS 人臉關鍵點檢測iOS
- 建立自己的.net類庫 (轉)
- 建立自己的家(網站) (轉)網站
- mysql 建立索引的方法--建立檢視MySql索引
- 異常點/離群點檢測演算法——LOF演算法
- js如何建立、刪除或者檢測cookie是否存在JSCookie
- 自己訓練SVM分類器進行HOG行人檢測HOG
- 自己寫的一些函式--對角陣為1,小對角陣全是1函式
- 技術分享 | Linux 入侵檢測中的程式建立監控Linux
- 建立併發布自己的nuget包
- Android 建立自己的Camera AppAndroidAPP
- hexo+github建立自己的blogHexoGithub
- **CI中建立你自己的類庫