侵蝕 erode

#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 )
{
<%%KEEPWHITESPACE%%>    src = cv::imread("/Users/powenko/Desktop/apple.png");
<%%KEEPWHITESPACE%%>    if (src.empty())
<%%KEEPWHITESPACE%%>    {
<%%KEEPWHITESPACE%%>        cerr << "No image supplied ..." << endl;
<%%KEEPWHITESPACE%%>        return -1;
<%%KEEPWHITESPACE%%>    }
<%%KEEPWHITESPACE%%>    const char* source_window = "Source";
<%%KEEPWHITESPACE%%>    namedWindow( source_window, WINDOW_AUTOSIZE );
<%%KEEPWHITESPACE%%>    imshow( source_window, src );
<%%KEEPWHITESPACE%%>    createTrackbar( " erode thresh:", "Source", &thresh, max_thresh, thresh_callback );
<%%KEEPWHITESPACE%%>    thresh_callback( 0, 0 );
<%%KEEPWHITESPACE%%>    waitKey(0);
<%%KEEPWHITESPACE%%>    return(0);
}
void thresh_callback(int, void* )
{
<%%KEEPWHITESPACE%%>    Mat canny_output;
<%%KEEPWHITESPACE%%>    vector<vector<Point> > contours;
<%%KEEPWHITESPACE%%>    vector<Vec4i> hierarchy;
<%%KEEPWHITESPACE%%>    //kernel的形狀----矩形: MORPH_RECT  交叉形: MORPH_CROSS   椭圆形 : MORPH_ELLIPSE
<%%KEEPWHITESPACE%%>    Mat drawing;
<%%KEEPWHITESPACE%%>    if(thresh>0){
<%%KEEPWHITESPACE%%>        Mat element = getStructuringElement(MORPH_RECT,	 Size(thresh,thresh));
<%%KEEPWHITESPACE%%>        erode(src, drawing, element);
<%%KEEPWHITESPACE%%>    }else{
<%%KEEPWHITESPACE%%>        drawing=src;

<%%KEEPWHITESPACE%%>    }
<%%KEEPWHITESPACE%%>    namedWindow( "Contours", WINDOW_AUTOSIZE );
<%%KEEPWHITESPACE%%>    imshow( "Contours", drawing );
}

screen-shot-2016-11-28-at-11-49-39-am

 

 

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