膨脹 dilate

#include <iostream>
#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>

using namespace cv ;
using namespace std ;
Mat src; Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
void thresh_callback(int, void* );
int main( int, char** argv )
{
    src = cv::imread("/Users/powenko/Desktop/apple.png");
    if (src.empty())
    {
        cerr << "No image supplied ..." << endl;
        return -1;
    }
    const char* source_window = "Source";
    namedWindow( source_window, WINDOW_AUTOSIZE );
    imshow( source_window, src );
    createTrackbar( " erode thresh:", "Source", &thresh, max_thresh, thresh_callback );
    thresh_callback( 0, 0 );
    waitKey(0);
    return(0);
}
void thresh_callback(int, void* )
{
    Mat canny_output;
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    //kernel的形狀----矩形: MORPH_RECT  交叉形: MORPH_CROSS   椭圆形 : MORPH_ELLIPSE
    Mat drawing;
    if(thresh>0){
        Mat element = getStructuringElement(MORPH_RECT,	 Size(thresh,thresh));
        dilate(src, drawing, element);
    }else{
        drawing=src;
        
    }
    namedWindow( "Contours", WINDOW_AUTOSIZE );
    imshow( "Contours", drawing );
}

screen-shot-2016-11-28-at-12-11-45-pm

OpenCV
CH01 簡介CH02 OpenCV APICH03 繪圖CH04 應用範例CH06 haarcascadesCH06 surf和siftCH07 OCRCH09 FaceCH5 輪廓(findContours、drawContours)