\brief DrawData \param frame \param tracks \param framesCounter \param currTime
| 896 | /// \param currTime |
| 897 | /// |
| 898 | void DrawData(cv::Mat frame, const std::vector<TrackingObject>& tracks, int framesCounter, int currTime) override |
| 899 | { |
| 900 | m_logger->info("Frame {0} ({1}): tracks = {2}, time = {3}", framesCounter, m_framesCount, tracks.size(), currTime); |
| 901 | |
| 902 | static float averFps = 0; |
| 903 | if (averFps == 0) |
| 904 | averFps = 1000.f / currTime; |
| 905 | else |
| 906 | averFps = 0.9f * averFps + 0.1f * (1000.f / currTime); |
| 907 | cv::putText(frame, std::to_string(cvRound(averFps)) + " fps", cv::Point(10, 40), cv::FONT_HERSHEY_TRIPLEX, (frame.cols > 1000) ? 1.5 : 1.0, cv::Scalar(255, 0, 255)); |
| 908 | |
| 909 | for (const auto& track : tracks) |
| 910 | { |
| 911 | if (track.IsRobust(2, // Minimal trajectory size |
| 912 | 0.5f, // Minimal ratio raw_trajectory_points / trajectory_lenght |
| 913 | cv::Size2f(0.1f, 8.0f), 2)) // Min and max ratio: width / height |
| 914 | { |
| 915 | DrawTrack(frame, track, true, framesCounter); |
| 916 | |
| 917 | std::stringstream label; |
| 918 | label << TypeConverter::Type2Str(track.m_type) << " " << std::setprecision(2) << track.m_velocity << ": " << track.m_confidence; |
| 919 | int baseLine = 0; |
| 920 | cv::Size labelSize = cv::getTextSize(label.str(), cv::FONT_HERSHEY_TRIPLEX, 0.5, 1, &baseLine); |
| 921 | |
| 922 | cv::Rect brect = track.m_rrect.boundingRect(); |
| 923 | if (brect.x < 0) |
| 924 | { |
| 925 | brect.width = std::min(brect.width, frame.cols - 1); |
| 926 | brect.x = 0; |
| 927 | } |
| 928 | else if (brect.x + brect.width >= frame.cols) |
| 929 | { |
| 930 | brect.x = std::max(0, frame.cols - brect.width - 1); |
| 931 | brect.width = std::min(brect.width, frame.cols - 1); |
| 932 | } |
| 933 | if (brect.y - labelSize.height < 0) |
| 934 | { |
| 935 | brect.height = std::min(brect.height, frame.rows - 1); |
| 936 | brect.y = labelSize.height; |
| 937 | } |
| 938 | else if (brect.y + brect.height >= frame.rows) |
| 939 | { |
| 940 | brect.y = std::max(0, frame.rows - brect.height - 1); |
| 941 | brect.height = std::min(brect.height, frame.rows - 1); |
| 942 | } |
| 943 | //DrawFilledRect(frame, cv::Rect(cv::Point(brect.x, brect.y - labelSize.height), cv::Size(labelSize.width, labelSize.height + baseLine)), cv::Scalar(200, 200, 200), 150); |
| 944 | //cv::putText(frame, label.str(), brect.tl(), cv::FONT_HERSHEY_TRIPLEX, 0.5, cv::Scalar(0, 0, 0)); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | //m_detector->CalcMotionMap(frame); |
| 949 | } |
| 950 | }; |
| 951 | |
| 952 | #endif |