OpenCV實現(xiàn)圖像角點檢測
更新時間:2019年01月12日 13:33:07 作者:lindamtd
這篇文章主要為大家詳細(xì)介紹了OpenCV實現(xiàn)圖像角點檢測,具有一定的參考價值,感興趣的小伙伴們可以參考一下
歷時一個多月,于今天上午終于將項目交上去了,這期間雖很辛苦,但是成長了不少,在此將項目中涉及到的知識點進行整理,本文主要介紹圖像的角點檢測:
一、代碼部分:
// Detect_Corners.cpp : 定義控制臺應(yīng)用程序的入口點。 // #include "stdafx.h" #include "opencv2/opencv.hpp" #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include "opencv2/highgui/highgui.hpp" #include <stdio.h> #include <stdlib.h> using namespace std; using namespace cv; //全局變量 Mat src, src_gray; int thresh = 200; int max_thresh = 255; char* source_window = "Source image"; //char* corners_window = "Corners detected"; //函數(shù)聲明 void cornerHarris_demo(int, void*); int _tmain(int argc, _TCHAR* argv[]) { //Load source image and convert it to gray char *img_name="..\\image\\71254.png"; src=imread(img_name); imshow(source_window,src); cvtColor(src, src_gray, CV_BGR2GRAY); createTrackbar("Threshold: ", source_window, &thresh, max_thresh, cornerHarris_demo); waitKey(0); //角點檢測 cornerHarris_demo(0,0); return 0; } /** 函數(shù) cornerHarris_demo */ void cornerHarris_demo( int, void*) { Mat dst, dst_norm,dst_norm_scaled; dst = Mat::zeros(src.size(), CV_32FC1 ); // Detector parameters int blockSize = 2; int apertureSize = 3; double k = 0.04; // Detecting corners cornerHarris( src_gray, dst, blockSize, apertureSize, k, BORDER_DEFAULT ); // Normalizing normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() ); convertScaleAbs( dst_norm, dst_norm_scaled ); // Drawing a circle around corners for( int j = 0; j < dst_norm.rows ; j++ ) { for( int i = 0; i < dst_norm.cols; i++ ) { if( (int) dst_norm.at<float>(j,i) > thresh ) { circle( dst_norm_scaled, Point(i, j), 5, Scalar(0), 2, 8, 0 ); circle(src,Point( i, j ), 5, Scalar(255,0,0), -1, 8, 0 ); } } } // Showing the result imshow( source_window, src); }
二、檢測效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
makefile如何調(diào)用靜態(tài)庫的方法實現(xiàn)
這篇文章主要介紹了makefile如何調(diào)用靜態(tài)庫的方法實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12