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();
}
n-dimensional dense array class
Definition mat.hpp:829
_Tp y
y coordinate of the point
Definition types.hpp:202
_Tp x
x coordinate of the point
Definition types.hpp:201
#define CV_8UC3
Definition interface.h:90
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void fillPoly(InputOutputArray img, InputArrayOfArrays pts, const Scalar &color, int lineType=LINE_8, int shift=0, Point offset=Point())
Fills the area bounded by one or more polygons.
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)
Draws a text string.
void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws several polygonal curves.
float intersectConvexConvex(InputArray p1, InputArray p2, OutputArray p12, bool handleNested=true)
Finds intersection of two convex polygons.
bool isContourConvex(InputArray contour)
Tests a contour convexity.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3