使用opencv3.3进行岭回归

来源:互联网 发布:美工电脑配置清单2017 编辑:程序博客网 时间:2024/05/01 05:27
// 分水岭.cpp: 对图片用分水岭算法进行分割
//#include "stdafx.h"#include<opencv2\highgui\highgui.hpp>#include<imgproc\imgproc.hpp>#include<iostream>using namespace cv;using namespace std;int main(){Mat srcImage = imread("source.jpg", 0);Mat dstImage = imread("source.jpg");//cvtColor(srcImage, grayImage, COLOR_BGR2GRAY);//将彩色图像转成灰色图像imshow("原图像", srcImage);imshow("彩色图像", dstImage);//对图像做一个二值化srcImage = srcImage > 90;imshow("二值化的图像", srcImage);//利用findContours()函数找出边缘vector<vector<Point> > contours;vector<Vec4i> hierachy;findContours(srcImage, contours, hierachy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);//开始把找出的边缘画出来Mat mask_img(dstImage.size(), CV_8UC3);int index = 0;for (; index >= 0; index = hierachy[index][0]){Scalar color(rand() & 255, rand() & 255, rand() & 255);drawContours(mask_img, contours, index, color, CV_FILLED, 8, hierachy);}imshow("画出边缘的图像", mask_img);//进行岭回归watershed(dstImage, mask_img);//岭回归后mask_img的样子Mat afterWatershed;convertScaleAbs(mask_img, afterWatershed);imshow("岭回归之后的图像",afterWatershed );waitKey(0);return 0;}

原创粉丝点击