#include <math.h>
#include <iostream>
static void help(char** argv)
{
cout
<< "\n此程式演示了 findContours 和 drawContours 的用法\n"
<< "原始影像與繪製輪廓的影像一起顯示\n"
<< "用法:\n";
cout
<< argv[0]
<< "建立一個軌跡條,用於控制輪廓級別,範圍從 -3 到 3\n"
<< endl;
}
const int w = 500;
int levels = 3;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
static void on_trackbar(int, void*)
{
int _levels = levels - 3;
drawContours( cnt_img, contours, _levels <= 0 ? 3 : -1,
Scalar(128,255,255),
3, LINE_AA, hierarchy, std::abs(_levels) );
imshow("contours", cnt_img);
}
int main(
int argc,
char** argv)
{
if (parser.has("help"))
{
help(argv);
return 0;
}
for( int i = 0; i < 6; i++ )
{
int dx = (i%2)*250 - 30;
int dy = (i/2)*150;
if( i == 0 )
{
for( int j = 0; j <= 10; j++ )
{
double angle = (j+5)*
CV_PI/21;
}
}
ellipse( img,
Point(dx+150, dy+100),
Size(100,70), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+115, dy+70),
Size(30,20), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+185, dy+70),
Size(30,20), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+115, dy+70),
Size(15,15), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+185, dy+70),
Size(15,15), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+115, dy+70),
Size(5,5), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+185, dy+70),
Size(5,5), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+150, dy+100),
Size(10,5), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+150, dy+150),
Size(40,10), 0, 0, 360, black, -1, 8, 0 );
ellipse( img,
Point(dx+27, dy+100),
Size(20,35), 0, 0, 360, white, -1, 8, 0 );
ellipse( img,
Point(dx+273, dy+100),
Size(20,35), 0, 0, 360, white, -1, 8, 0 );
}
vector<vector<Point> > contours0;
findContours( img, contours0, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
contours.resize(contours0.size());
for( size_t k = 0; k < contours0.size(); k++ )
on_trackbar(0,0);
return 0;
}
如果陣列沒有元素,則返回 true。
int64_t int64
用於指定影像或矩形大小的模板類。
Definition types.hpp:335
#define CV_8UC1
定義 interface.h:88
Quat< T > cos(const Quat< T > &q)
Quat< T > sin(const Quat< T > &q)
int cvRound(double value)
將浮點數舍入為最接近的整數。
Definition fast_math.hpp:200
#define CV_PI
定義 cvdef.h:380
void imshow(const String &winname, InputArray mat)
在指定視窗中顯示影像。
int waitKey(int delay=0)
等待按鍵按下。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
建立視窗。
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
建立滑動條並將其附加到指定視窗。
void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製簡單或粗橢圓弧或填充橢圓扇區。
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製連線兩點的線段。
void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool closed)
以指定精度逼近多邊形曲線。
void findContours(InputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
在二值影像中查詢輪廓。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3