canny与findcontours()的区别:
虽然canny之类的边缘检测算法可以根据像素间的差异检测出轮廓边界的像素,但是它并没有将轮廓作为一个整体。下一步是要把这些像素组装成轮廓,这个函数就是findcontours()。
findContours(dist,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE,Point());
CV_RETR_EXTERNAL 与 CV_CHAIN_APPROX_SIMPLE 结合可用来连通区域计数,数量直接由contours.size()表示。
opencv轮廓检测的函数:findContours()与drawContours()的使用
#include <iostream>
//#include <stdio.h>
#include <vector> //提示 “vector”: 未声明的标识符时需要加的
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using std::vector; //提示 “vector”: 未声明的标识符时需要加的
int main()
{
cv::Mat srcImage; //原始图像
srcImage = cv::imread("F:\\opencv\\fish\\build-untitled2-Desktop_Qt_5_9_0_MSVC2017_64bit-Release\\3.png");
if(!srcImag