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;
}
{
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;
}
Designed for command line parsing.
Definition: utility.hpp:818
n-dimensional dense array class
Definition: mat.hpp:811
CV_NODISCARD_STD Mat clone() const
Creates a full copy of the array and the underlying data.
MatSize size
Definition: mat.hpp:2138
void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray())
computes bitwise conjunction of the two arrays (dst = src1 & src2) Calculates the per-element bit-wis...
Point2i Point
Definition: types.hpp:204
std::string String
Definition: cvstd.hpp:152
Scalar_< double > Scalar
Definition: types.hpp:691
#define CV_8UC1
Definition: interface.h:88
#define CV_8UC3
Definition: interface.h:90
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
@ circle
Definition: gr_skig.hpp:62
GMat mask(const GMat &src, const GMat &mask)
Applies a mask to a matrix.
@ EVENT_MBUTTONDOWN
indicates that the middle mouse button is pressed.
Definition: highgui.hpp:214
@ EVENT_LBUTTONUP
indicates that left mouse button is released.
Definition: highgui.hpp:215
@ EVENT_RBUTTONDOWN
indicates that the right mouse button is pressed.
Definition: highgui.hpp:213
@ EVENT_RBUTTONUP
indicates that right mouse button is released.
Definition: highgui.hpp:216
@ EVENT_LBUTTONDOWN
indicates that the left mouse button is pressed.
Definition: highgui.hpp:212
@ WINDOW_AUTOSIZE
the user cannot resize the window, the size is constrainted by the image displayed.
Definition: highgui.hpp:188
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 namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
void setMouseCallback(const String &winname, MouseCallback onMouse, void *userdata=0)
Sets mouse handler for the specified window.
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
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 line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
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.
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106