Skip to content

Instantly share code, notes, and snippets.

@sagi-z
Last active July 9, 2017 05:18
Show Gist options
  • Save sagi-z/01fe800ba2c4cfdab2baae42f7438567 to your computer and use it in GitHub Desktop.
Save sagi-z/01fe800ba2c4cfdab2baae42f7438567 to your computer and use it in GitHub Desktop.
int main()
{
Mat image = Mat::zeros(768, 1024, CV_8UC3);
Canvas c("Counting People", image.size());
c.enableScreenText();
help(c);
c.enableStatusMsg();
c.setShapeType(LineCrossing::type); // default shape type for direct GUI creation
namedWindow("Counting People", WINDOW_AUTOSIZE);
c.setMouseCallback(); // optional for mouse usage see also (example_selectbox.cpp)
TrackerSimulator tracker(c);
auto buttonAlignment = VerticalLayout::create(c);
buttonAlignment->setStretchXToParent(true);
auto button = Button::create(*buttonAlignment,
Point(image.cols / 2, 0),
"Start / Stop\nSimulation",
"", [&tracker](Widget *w)
{
tracker.setSimulatorOn(! tracker.getSimulatorOn());
});
button->setLayoutAnchor(Widget::CENTER);
int minStepsPerSeconds = min(image.cols / 2, image.rows / 2) / 10;
int maxStepsPerSeconds = max(image.cols / 2, image.rows / 2) / 10;
Point center(image.cols / 2, image.rows / 2);
int key = 0;
Mat out;
int fps = 25;
int delay = 1000 / fps;
do
{
tracker.simulate(2, center, 50, minStepsPerSeconds, maxStepsPerSeconds);
switch (key)
{
case 'h':
help(c);
break;
case 's':
c.writeShapesToFile("line-crossings.xml");
break;
case 'l':
c.readShapesFromFile("line-crossings.xml");
break;
case 65535:
c.deleteActive();
break;
}
c.redrawOn(image, out);
c.imshow(out);
key = c.waitKeyEx(delay); // GUI and callbacks happen here
} while (key != 'q');
destroyAllWindows();
c.clearShapes(); // workaround for v1.0.0
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment