W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
在本教程中,您將學(xué)習(xí)如何:
該Canny邊緣檢測(cè)是由約翰·F·坎尼在1986年也知道很多的開發(fā)最佳的檢測(cè),坎尼算法旨在滿足三個(gè)主要標(biāo)準(zhǔn):
應(yīng)用一對(duì)卷積面罩 (在 x 和 y directions:
查找梯度強(qiáng)度和方向:
方向四舍五入為四個(gè)可能的角度之一(即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";
請(qǐng)注意以下事項(xiàng):
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號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: