This program demonstrates using mouse events and how to make and use a mask image (black and white) .
#include <iostream>
vector<Point> pts;
int drag = 0;
int var = 0;
int flag = 0;
void mouseHandler(int, int, int, int, void*);
void mouseHandler(int event, int x, int y, int, void*)
{
{
if (flag == 0)
{
if (var == 0)
pts.push_back(point);
var++;
drag = 1;
if (var > 1)
line(img1,pts[var-2], point,
Scalar(0, 0, 255), 2, 8, 0);
}
}
{
drag = 0;
}
{
flag = 1;
if (var != 0)
{
}
}
{
flag = var;
vector<vector<Point> > vpts;
}
{
pts.clear();
var = 0;
drag = 0;
flag = 0;
}
}
int main(int argc, char **argv)
{
parser.about("This program demonstrates using mouse events\n");
parser.printMessage();
cout << "\n\tleft mouse button - set a point to create mask shape\n"
"\tright mouse button - create mask from points\n"
"\tmiddle mouse button - reset\n";
if (src.empty())
{
printf("Error opening image: %s\n", input_image.c_str());
return 0;
}
return 0;
}