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

Method DrawTrack

example/CarsCounting.cpp:35–132  ·  view source on GitHub ↗

\brief CarsCounting::DrawTrack \param frame \param track \param drawTrajectory \param framesCounters

Source from the content-addressed store, hash-verified

33/// \param framesCounters
34///
35void CarsCounting::DrawTrack(cv::Mat frame, const TrackingObject& track, bool drawTrajectory, int framesCounter, const std::string& /*userLabel*/)
36{
37 cv::Rect brect = track.m_rrect.boundingRect();
38
39 m_resultsLog.AddTrack(framesCounter, track.m_ID, brect, track.m_type, track.m_confidence);
40 m_resultsLog.AddRobustTrack(track.m_ID);
41
42 if (track.m_isStatic)
43 {
44#if (CV_VERSION_MAJOR >= 4)
45 cv::rectangle(frame, brect, cv::Scalar(255, 0, 255), 2, cv::LINE_AA);
46#else
47 cv::rectangle(frame, brect, cv::Scalar(255, 0, 255), 2, CV_AA);
48#endif
49 }
50 else
51 {
52#if (CV_VERSION_MAJOR >= 4)
53 cv::rectangle(frame, brect, cv::Scalar(0, 255, 0), 1, cv::LINE_AA);
54#else
55 cv::rectangle(frame, brect, cv::Scalar(0, 255, 0), 1, CV_AA);
56#endif
57
58 if (!m_geoParams.Empty())
59 {
60 int traceSize = static_cast<int>(track.m_trace.size());
61 int period = std::min(2 * cvRound(m_fps), traceSize);
62 const auto& from = m_geoParams.Pix2Geo(track.m_trace[traceSize - period]);
63 const auto& to = m_geoParams.Pix2Geo(track.m_trace[traceSize - 1]);
64 auto dist = DistanceInMeters(from, to);
65
66 std::stringstream label;
67 if (period >= cvRound(m_fps) / 4)
68 {
69 auto velocity = (3.6f * dist * m_fps) / period;
70 //std::cout << TypeConverter::Type2Str(track.m_type) << ": distance " << std::fixed << std::setw(2) << std::setprecision(2) << dist << " on time " << (period / m_fps) << " with velocity " << velocity << " km/h: " << track.m_confidence << std::endl;
71 if (velocity < 1.f || std::isnan(velocity))
72 velocity = 0;
73 //label << TypeConverter::Type2Str(track.m_type) << " " << std::fixed << std::setw(2) << std::setprecision(2) << velocity << " km/h";
74 label << TypeConverter::Type2Str(track.m_type) << " " << cvRound(velocity) << " km/h";
75
76 int baseLine = 0;
77 double fontScale = (frame.cols < 2000) ? 0.5 : 1.;
78 cv::Size labelSize = cv::getTextSize(label.str(), cv::FONT_HERSHEY_TRIPLEX, fontScale, 1, &baseLine);
79
80 if (brect.x < 0)
81 {
82 brect.width = std::min(brect.width, frame.cols - 1);
83 brect.x = 0;
84 }
85 else if (brect.x + brect.width >= frame.cols)
86 {
87 brect.x = std::max(0, frame.cols - brect.width - 1);
88 brect.width = std::min(brect.width, frame.cols - 1);
89 }
90 if (brect.y - labelSize.height < 0)
91 {
92 brect.height = std::min(brect.height, frame.rows - 1);

Callers

nothing calls this directly

Calls 8

DistanceInMetersFunction · 0.85
isnanFunction · 0.85
AddTrackMethod · 0.80
AddRobustTrackMethod · 0.80
EmptyMethod · 0.80
Pix2GeoMethod · 0.80
ID2ModuleMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected