static vector<Point> makeRectangle(
Point topLeft,
Point bottomRight)
{
vector<Point> rectangle;
rectangle.push_back(topLeft);
rectangle.push_back(
Point(bottomRight.
x, topLeft.
y));
rectangle.push_back(bottomRight);
rectangle.push_back(
Point(topLeft.
x, bottomRight.
y));
return rectangle;
}
static vector<Point> makeTriangle(
Point point1,
Point point2,
Point point3)
{
vector<Point> triangle;
triangle.push_back(point1);
triangle.push_back(point2);
triangle.push_back(point3);
return triangle;
}
static float drawIntersection(
Mat &image, vector<Point> polygon1, vector<Point> polygon2,
bool handleNested =
true)
{
vector<Point> intersectionPolygon;
vector<vector<Point> > polygons;
polygons.push_back(polygon1);
polygons.push_back(polygon2);
if (intersectArea > 0)
{
Scalar fillColor(200, 200, 200);
{
fillColor =
Scalar(0, 0, 255);
}
fillPoly(image, intersectionPolygon, fillColor);
}
return intersectArea;
}
static void drawDescription(
Mat &image,
int intersectionArea,
string description,
Point origin)
{
const size_t bufSize=1024;
char caption[bufSize];
snprintf(caption, bufSize, "Intersection area: %d%s", intersectionArea, description.c_str());
putText(image, caption, origin, FONT_HERSHEY_SIMPLEX, 0.6,
Scalar(0, 0, 0));
}
static void intersectConvexExample()
{
float intersectionArea;
intersectionArea = drawIntersection(image,
drawDescription(image, (
int)intersectionArea,
"",
Point(70, 40));
intersectionArea = drawIntersection(image,
drawDescription(image, (
int)intersectionArea,
"",
Point(70, 100));
intersectionArea = drawIntersection(image,
true);
drawDescription(image, (
int)intersectionArea,
" (handleNested true)",
Point(70, 160));
intersectionArea = drawIntersection(image,
false);
drawDescription(image, (
int)intersectionArea,
" (handleNested false)",
Point(70, 220));
intersectionArea = drawIntersection(image,
true);
drawDescription(image, (
int)intersectionArea,
" (handleNested true)",
Point(70, 280));
intersectionArea = drawIntersection(image,
false);
drawDescription(image, (
int)intersectionArea,
" (handleNested false)",
Point(70, 340));
intersectionArea = drawIntersection(image,
false);
drawDescription(image, (
int)intersectionArea,
" (handleNested false)",
Point(70, 400));
intersectionArea = drawIntersection(image,
false);
drawDescription(image, (
int)intersectionArea,
" (handleNested false)",
Point(70, 460));
intersectionArea = drawIntersection(image,
false);
drawDescription(image, (
int)intersectionArea,
"",
Point(70, 520));
vector<Point> notConvex;
notConvex.push_back(
Point(25, 560));
notConvex.push_back(
Point(25, 590));
notConvex.push_back(
Point(45, 580));
notConvex.push_back(
Point(60, 600));
notConvex.push_back(
Point(60, 550));
notConvex.push_back(
Point(45, 570));
intersectionArea = drawIntersection(image,
notConvex,
false);
drawDescription(image, (
int)intersectionArea,
" (invalid input: not convex)",
Point(70, 580));
imshow(
"Intersections", image);
}
{
intersectConvexExample();
}
_Tp y
点的 y 坐标
定义 types.hpp:202
_Tp x
点的 x 坐标
定义 types.hpp:201
#define CV_8UC3
定义 interface.h:90
void imshow(const String &winname, InputArray mat)
在指定的窗口中显示图像。
int waitKey(int delay=0)
等待按键按下。
void fillPoly(InputOutputArray img, InputArrayOfArrays pts, const Scalar &color, int lineType=LINE_8, int shift=0, Point offset=Point())
填充由一个或多个多边形包围的区域。
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
绘制文本字符串。
void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制多个多边形曲线。
float intersectConvexConvex(InputArray p1, InputArray p2, OutputArray p12, bool handleNested=true)
查找两个凸多边形的交点。
bool isContourConvex(InputArray contour)
测试轮廓的凸性。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3
磁盘上与文件关联的文件存储的“黑盒”表示。
定义 core.hpp:102