opencv边缘检测C++
时间: 2023-09-14 18:13:54 浏览: 109
Edge-Detection.zip_opencv 边缘检测
在OpenCV中进行边缘检测可以使用Canny算子、Sobel算子、Laplacian算子和Scharr滤波器等方法。在C++中,可以使用OpenCV库函数来实现边缘检测。以下是一个示例代码:
```cpp
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main() {
Mat srcImage, grayImage;
srcImage = imread("/Users/dwz/Desktop/cpp/1.jpg");
Mat srcImage1 = srcImage.clone();
cvtColor(srcImage, grayImage, COLOR_BGR2GRAY);
Mat dstImage, edge;
blur(grayImage, grayImage, Size(3,3));
Canny(grayImage, edge, 150, 100, 3);
dstImage.create(srcImage1.size(), srcImage1.type());
dstImage = Scalar::all(0);
srcImage1.copyTo(dstImage, edge);
imwrite("canny.jpg", dstImage);
return 0;
}
```
这段代码使用了Canny算子进行边缘检测。首先读取原始图像,然后将其转换为灰度图像。接下来对灰度图像进行模糊处理,并使用Canny算子进行边缘检测。最后将边缘检测结果与原始图像合并,并保存为"canny.jpg"。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [【OpenCV(C++)】图像变换:边缘检测](https://blog.csdn.net/weixin_43645790/article/details/104089225)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [OpenCV之Canny边缘检测(C++实现)](https://blog.csdn.net/xddwz/article/details/111585648)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文