123456789101112131415161718192021222324252627282930313233343536373839404142434445#
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 );
}