static vector<Point> makeRectangle(
Point topLeft,
Point bottomRight)
{
rectangle.push_back(topLeft);
rectangle.push_back(
Point(bottomRight.
x, topLeft.
y));
rectangle.push_back(bottomRight);
rectangle.push_back(
Point(topLeft.
x, bottomRight.
y));
}
static vector<Point> makeTriangle(
Point point1,
Point point2,
Point point3)
{
triangle.push_back(point1);
triangle.push_back(point2);
triangle.push_back(point3);
}
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);
}
vector<vector<Point> > pp;
pp.push_back(intersectionPolygon);
}
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());
}
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);
}
int main()
{
intersectConvexExample();
}