C++?opencv圖像處理實現(xiàn)圖片邊緣檢測示例
邊緣檢測簡介
邊緣檢測是圖像處理和計算機視覺中的基本問題,邊緣檢測的目的是標(biāo)識數(shù)字圖像中亮度變化明顯的點。
圖像邊緣檢測大幅度地減少了數(shù)據(jù)量,并且剔除量不相關(guān)的信息,保留了圖像重要的結(jié)構(gòu)屬性。
一、邊緣檢測步驟
1.圖像獲取
2.圖像濾波
3.圖像增強
4.圖像檢測
5.圖像定位
二、Canny
1.函數(shù)
void Canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false); image 8位輸入圖像 edges 單通道8位圖像 threshold1 遲滯過程第一個閾值 threshold2 遲滯過程第二個閾值 apertureSize 算子的孔徑大小 L2gradient 范數(shù)
2.代碼
#include<iostream>
#include<opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img1;
img1 = imread("圖片1.png", 0);
imshow("原圖", img1);
Canny(img1, img1,10, 10);
imshow("Canny", img1);
waitKey(0);
}
效果如下:

二、Sobel
1.函數(shù)
void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT); src 輸入 dst 輸出 ddepth 輸出圖像的數(shù)據(jù)類型 dx x方向的差分階數(shù) dy y方向的差分階數(shù) Ksize 尺寸 1,3,5,7 scale 縮放因子 delta 偏值 borderType 邊界像素模式
2.代碼
int main()
{
Mat img1, img2;
img1 = imread("圖片1.png", 0);
imshow("原圖", img1);
Sobel(img1, img2, CV_8U, 2,0,1);
imshow("sobel", img2);
waitKey(0);
}
效果如下:

三、Scharr
1.函數(shù)
void Scharr(InputArray src, OutputArray dst, int ddepth, int dx, int dy, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT); src 輸入 dst 輸出 ddepth 輸出圖像的數(shù)據(jù)類型 dx x方向的導(dǎo)數(shù) dy y方向的導(dǎo)數(shù) scale 縮放因子 delta 偏值 borderType 邊界像素模式
2.代碼
int main()
{
Mat img1, img2;
img1 = imread("圖片1.png", 0);
imshow("原圖", img1);
Scharr(img1, img2, CV_8U, 1, 0);
imshow("Scharr", img2);
waitKey(0);
}
效果如下:

四、Laplacian
1.函數(shù)
void Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize = 1, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT); src 輸入 dst 輸出 ddepth 輸出圖像的數(shù)據(jù)類型 Ksize 濾波器大小 正奇數(shù) scale 縮放因子 delta 偏值 borderType 邊界像素模式
2.代碼
int main()
{
Mat img1, img2;
img1 = imread("圖片1.png", 0);
imshow("原圖", img1);
Laplacian(img1, img2,CV_8U,1);
imshow("Laplacian", img2);
waitKey(0);
}
效果如下:

總結(jié)
本文只是簡單介紹了幾種常用的邊緣檢測算法函數(shù),都是調(diào)用函數(shù)解決問題,大家可以更加深入的研究數(shù)學(xué)方式的邊緣檢測算法,更多關(guān)于C++ opencv圖片邊緣檢測的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
kernel利用pt?regs劫持seq?operations的遷移過程詳解
這篇文章主要為大家介紹了kernel利用pt_regs劫持seq_operations進行遷移的過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05
C語言利用goto語句設(shè)計實現(xiàn)一個關(guān)機程序
今天給大家分享一個非常有趣的知識——用goto語句編寫一個關(guān)機小程序。主要用到了shutdown命令語句、goto語句、strcmp函數(shù)等知識點,感興趣的可以了解一下2023-01-01
關(guān)于STL中l(wèi)ist容器的一些總結(jié)
list就是數(shù)據(jù)結(jié)構(gòu)中的雙向鏈表(根據(jù)sgi stl源代碼),因此它的內(nèi)存空間是不連續(xù)的,通過指針來進行數(shù)據(jù)的訪問,這個特點使得它的隨即存取變的非常沒有效率,因此它沒有提供[]操作符的重載2013-09-09

