@@ -207,50 +207,50 @@ void CarsCounting::DrawTrack(cv::Mat frame,
207207 cv::rectangle (frame, ResizeRect (track.m_rrect .boundingRect ()), cv::Scalar (0 , 255 , 0 ), 1 , CV_AA );
208208#endif
209209
210- if (!m_geoParams.Empty ())
211- {
212- size_t period = 2 * cvRound (m_fps);
213- if (period >= track.m_trace .size ())
214- period = track.m_trace .size ();
215- const auto & from = m_geoParams.Pix2Geo (track.m_trace [track.m_trace .size () - period]);
216- const auto & to = m_geoParams.Pix2Geo (track.m_trace [track.m_trace .size () - 1 ]);
217- auto dist = DistanceInMeters (from, to);
218-
219- std::stringstream label;
220- if (period >= cvRound (m_fps) / 4 )
221- {
222- auto velocity = (3 .6f * dist * m_fps) / period;
223- // std::cout << 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;
224- if (velocity < 1 .f || std::isnan (velocity))
225- velocity = 0 ;
226- label << track.m_type << " " << std::fixed << std::setw (2 ) << std::setprecision (2 ) << velocity << " km/h" ;
227-
228- int baseLine = 0 ;
229- double fontScale = 0.5 ;
230- cv::Size labelSize = cv::getTextSize (label.str (), cv::FONT_HERSHEY_SIMPLEX , fontScale, 1 , &baseLine);
231-
232- cv::Rect brect = track.m_rrect .boundingRect ();
233- if (brect.x < 0 )
234- {
235- brect.width = std::min (brect.width , frame.cols - 1 );
236- brect.x = 0 ;
237- }
238- else if (brect.x + brect.width >= frame.cols )
239- {
240- brect.x = std::max (0 , frame.cols - brect.width - 1 );
241- brect.width = std::min (brect.width , frame.cols - 1 );
242- }
243- if (brect.y - labelSize.height < 0 )
244- {
245- brect.height = std::min (brect.height , frame.rows - 1 );
246- brect.y = labelSize.height ;
247- }
248- else if (brect.y + brect.height >= frame.rows )
249- {
250- brect.y = std::max (0 , frame.rows - brect.height - 1 );
251- brect.height = std::min (brect.height , frame.rows - 1 );
252- }
253- cv::rectangle (frame, cv::Rect (cv::Point (brect.x , brect.y - labelSize.height ), cv::Size (labelSize.width , labelSize.height + baseLine)), cv::Scalar (200 , 200 , 200 ), cv::FILLED );
210+ if (!m_geoParams.Empty ())
211+ {
212+ size_t period = 2 * cvRound (m_fps);
213+ if (period >= track.m_trace .size ())
214+ period = track.m_trace .size ();
215+ const auto & from = m_geoParams.Pix2Geo (track.m_trace [track.m_trace .size () - period]);
216+ const auto & to = m_geoParams.Pix2Geo (track.m_trace [track.m_trace .size () - 1 ]);
217+ auto dist = DistanceInMeters (from, to);
218+
219+ std::stringstream label;
220+ if (period >= cvRound (m_fps) / 4 )
221+ {
222+ auto velocity = (3 .6f * dist * m_fps) / period;
223+ // std::cout << 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;
224+ if (velocity < 1 .f || std::isnan (velocity))
225+ velocity = 0 ;
226+ label << track.m_type << " " << std::fixed << std::setw (2 ) << std::setprecision (2 ) << velocity << " km/h" ;
227+
228+ int baseLine = 0 ;
229+ double fontScale = 0.5 ;
230+ cv::Size labelSize = cv::getTextSize (label.str (), cv::FONT_HERSHEY_SIMPLEX , fontScale, 1 , &baseLine);
231+
232+ cv::Rect brect = track.m_rrect .boundingRect ();
233+ if (brect.x < 0 )
234+ {
235+ brect.width = std::min (brect.width , frame.cols - 1 );
236+ brect.x = 0 ;
237+ }
238+ else if (brect.x + brect.width >= frame.cols )
239+ {
240+ brect.x = std::max (0 , frame.cols - brect.width - 1 );
241+ brect.width = std::min (brect.width , frame.cols - 1 );
242+ }
243+ if (brect.y - labelSize.height < 0 )
244+ {
245+ brect.height = std::min (brect.height , frame.rows - 1 );
246+ brect.y = labelSize.height ;
247+ }
248+ else if (brect.y + brect.height >= frame.rows )
249+ {
250+ brect.y = std::max (0 , frame.rows - brect.height - 1 );
251+ brect.height = std::min (brect.height , frame.rows - 1 );
252+ }
253+ cv::rectangle (frame, cv::Rect (cv::Point (brect.x , brect.y - labelSize.height ), cv::Size (labelSize.width , labelSize.height + baseLine)), cv::Scalar (200 , 200 , 200 ), cv::FILLED );
254254 cv::putText (frame, label.str (), brect.tl (), cv::FONT_HERSHEY_SIMPLEX , fontScale, cv::Scalar (0 , 0 , 0 ));
255255 }
256256 }
@@ -380,9 +380,9 @@ bool CarsCounting::InitTracker(cv::UMat frame)
380380 }
381381
382382#if 0
383- std::vector<cv::Point> framePoints{ cv::Point(420, 348), cv::Point(509, 283), cv::Point(731, 281), cv::Point(840, 343) };
384- std::vector<cv::Point2f> geoPoints{ cv::Point2f(45.526646, 5.974535), cv::Point2f(45.527566, 5.973849), cv::Point2f(45.527904, 5.974135), cv::Point2f(45.526867, 5.974826) };
385- m_geoParams.SetKeyPoints(framePoints, geoPoints);
383+ std::vector<cv::Point> framePoints{ cv::Point(420, 348), cv::Point(509, 283), cv::Point(731, 281), cv::Point(840, 343) };
384+ std::vector<cv::Point2f> geoPoints{ cv::Point2f(45.526646, 5.974535), cv::Point2f(45.527566, 5.973849), cv::Point2f(45.527904, 5.974135), cv::Point2f(45.526867, 5.974826) };
385+ m_geoParams.SetKeyPoints(framePoints, geoPoints);
386386#endif
387387
388388 return res;
@@ -401,13 +401,13 @@ void CarsCounting::DrawData(cv::Mat frame, int framesCounter, int currTime)
401401 std::cout << " Frame " << framesCounter << " : tracks = " << tracks.size () << " , time = " << currTime << std::endl;
402402 }
403403
404- if (!m_geoParams.Empty ())
405- {
406- std::vector<cv::Point> points = m_geoParams.GetFramePoints ();
407- for (size_t i = 0 ; i < points.size (); ++i)
408- {
409- cv::line (frame, points[i % points.size ()], points[(i + 1 ) % points.size ()], cv::Scalar (255 , 255 , 255 ), 1 , cv::LINE_AA );
410- }
404+ if (!m_geoParams.Empty ())
405+ {
406+ std::vector<cv::Point> points = m_geoParams.GetFramePoints ();
407+ for (size_t i = 0 ; i < points.size (); ++i)
408+ {
409+ cv::line (frame, points[i % points.size ()], points[(i + 1 ) % points.size ()], cv::Scalar (255 , 255 , 255 ), 1 , cv::LINE_AA );
410+ }
411411 }
412412
413413 for (const auto & track : tracks)
0 commit comments