MCPcopy Create free account
hub / github.com/Smorodov/Multitarget-tracker / MouseTracking

Function MouseTracking

example/MouseExample.h:25–127  ·  view source on GitHub ↗

----------------------------------------------------------------------

Source from the content-addressed store, hash-verified

23
24// ----------------------------------------------------------------------
25void MouseTracking(cv::CommandLineParser parser)
26{
27 std::string outFile = parser.get<std::string>("out");
28
29 cv::VideoWriter writer;
30
31 int k = 0;
32 std::vector<cv::Scalar> colors = { cv::Scalar(255, 0, 0), cv::Scalar(0, 255, 0), cv::Scalar(0, 0, 255), cv::Scalar(255, 255, 0), cv::Scalar(0, 255, 255), cv::Scalar(255, 0, 255), cv::Scalar(255, 127, 255), cv::Scalar(127, 0, 255), cv::Scalar(127, 0, 127) };
33
34#ifndef SILENT_WORK
35 cv::namedWindow("Video");
36#endif
37
38 cv::Mat frame = cv::Mat(800, 800, CV_8UC3);
39
40 if (!outFile.empty() && !writer.isOpened())
41 writer.open(outFile, cv::VideoWriter::fourcc('h', '2', '6', '4'), 20, frame.size(), true);
42
43 // Set mouse callback
44 cv::Point2f pointXY;
45 cv::setMouseCallback("Video", mv_MouseCallback, (void*)&pointXY);
46
47 TrackerSettings settings;
48 settings.SetDistance(tracking::DistCenters);
49 settings.m_kalmanType = tracking::KalmanLinear;
50 settings.m_filterGoal = tracking::FilterCenter;
51 settings.m_lostTrackType = tracking::TrackNone;
52 settings.m_matchType = tracking::MatchHungrian;
53 settings.m_dt = 0.2f;
54 settings.m_accelNoiseMag = 0.5f;
55 settings.m_distThres = 0.8f;
56 settings.m_minAreaRadiusPix = frame.rows / 20.f;
57 settings.m_maximumAllowedLostTime = 1.;
58 settings.m_maxTraceLength = 1.;
59
60 std::unique_ptr<BaseTracker> tracker = BaseTracker::CreateTracker(settings);
61
62 track_t alpha = 0;
63 cv::RNG rng;
64 while (k != 27)
65 {
66 frame = cv::Scalar::all(0);
67
68 // Noise addition (measurements/detections simulation )
69 float Xmeasured = pointXY.x + static_cast<float>(rng.gaussian(2.0));
70 float Ymeasured = pointXY.y + static_cast<float>(rng.gaussian(2.0));
71
72 // Append circulating around mouse cv::Points (frequently intersecting)
73 std::vector<Point_t> pts;
74 pts.emplace_back(Xmeasured + 100.0f*sin(-alpha), Ymeasured + 100.0f*cos(-alpha));
75 pts.emplace_back(Xmeasured + 100.0f*sin(alpha), Ymeasured + 100.0f*cos(alpha));
76 pts.emplace_back(Xmeasured + 100.0f*sin(alpha / 2.0f), Ymeasured + 100.0f*cos(alpha / 2.0f));
77 pts.emplace_back(Xmeasured + 100.0f*sin(alpha / 3.0f), Ymeasured + 100.0f*cos(alpha / 1.0f));
78 alpha += 0.05f;
79
80 regions_t regions;
81 for (auto p : pts)
82 {

Callers 1

mainFunction · 0.85

Calls 10

sinFunction · 0.85
cosFunction · 0.85
CRegionClass · 0.85
openMethod · 0.80
SetDistanceMethod · 0.80
GetTracksMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected