W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
在本教程中,您將學習如何:
該Canny邊緣檢測是由約翰·F·坎尼在1986年也知道很多的開發(fā)最佳的檢測,坎尼算法旨在滿足三個主要標準:
應用一對卷積面罩 (在 x 和 y directions:
查找梯度強度和方向:
方向四舍五入為四個可能的角度之一(即0,45,90或135)
Canny推薦上限:2:1和3:1之間的較低比例。
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
Mat src, src_gray;
Mat dst, detected_edges;
int edgeThresh = 1;
int lowThreshold;
int const max_lowThreshold = 100;
int ratio = 3;
int kernel_size = 3;
const char* window_name = "Edge Map";
static void CannyThreshold(int, void*)
{
blur( src_gray, detected_edges, Size(3,3) );
Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
dst = Scalar::all(0);
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
}
int main( int, char** argv )
{
src = imread( argv[1], IMREAD_COLOR ); // Load an image
if( src.empty() )
{ return -1; }
dst.create( src.size(), src.type() );
cvtColor( src, src_gray, COLOR_BGR2GRAY );
namedWindow( window_name, WINDOW_AUTOSIZE );
createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );
CannyThreshold(0, 0);
waitKey(0);
return 0;
}
Mat src, src_gray;
Mat dst, detected_edges;
int edgeThresh = 1;
int lowThreshold;
int const max_lowThreshold = 100;
int ratio = 3;
int kernel_size = 3;
const char* window_name = "Edge Map";
請注意以下事項:
src = imread( argv[1], IMREAD_COLOR ); // Load an image
if( src.empty() )
{ return -1; }
dst.create(src.size(),src.type());
cvtColor(src,src_gray,COLOR_BGR2GRAY);
namedWindow(window_name,WINDOW_AUTOSIZE);
createTrackbar(“Min Threshold:”,window_name,&lowThreshold,max_lowThreshold,CannyThreshold);
觀察以下內(nèi)容:
blur(src_gray,detected_edges,Size(3,3));
Canny(detected_edges,detected_edges,lowThreshold,lowThreshold * ratio,kernel_size);
其中的解釋:
dst = Scalar :: all(0);
src.copyTo(dst,detected_edges);
imshow(window_name,dst);
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: