小白学视觉,笔记,扩展
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img, imgGray, imgMask, img_;
Mat maskWaterShed; // watershed()函数的参数
img = imread("lenaw.png"); //含有标记的图像
img_ = imread("lena.png"); //原图像
cvtColor(img, imgGray, COLOR_BGR2GRAY);
//二值化并开运算
threshold(imgGray, imgMask, 254, 255, THRESH_BINARY);
Mat k = getStructuringElement(0, Size(3, 3));
morphologyEx(imgMask, imgMask, MORPH_OPEN, k);
imshow("含有标记的图像", img);
imshow("原图像", img_);
imshow("imgMask", imgMask);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(imgMask, conto