Skip to content

Commit

Permalink
Merge pull request #424 from Nuzhny007/master
Browse files Browse the repository at this point in the history
Add map view to CarsCounting example
  • Loading branch information
Nuzhny007 committed Aug 6, 2023
2 parents f4cff0f + af7de35 commit 51b8386
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 8 additions & 2 deletions example/CarsCounting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void CarsCounting::DrawTrack(cv::Mat frame, const TrackingObject& track, bool dr
label << TypeConverter::Type2Str(track.m_type) << " " << cvRound(velocity) << " km/h";

int baseLine = 0;
double fontScale = 0.5;
double fontScale = (frame.cols < 2000) ? 0.5 : 1.;
cv::Size labelSize = cv::getTextSize(label.str(), cv::FONT_HERSHEY_TRIPLEX, fontScale, 1, &baseLine);

if (brect.x < 0)
Expand Down Expand Up @@ -232,7 +232,7 @@ void CarsCounting::DrawData(cv::Mat frame, const std::vector<TrackingObject>& tr
if (m_showLogs)
std::cout << "Frame " << framesCounter << ": tracks = " << tracks.size() << ", time = " << currTime << std::endl;

#if 0 // Debug output
#if 1 // Debug output
if (!m_geoParams.Empty())
{
std::vector<cv::Point> points = m_geoParams.GetFramePoints();
Expand Down Expand Up @@ -273,6 +273,12 @@ void CarsCounting::DrawData(cv::Mat frame, const std::vector<TrackingObject>& tr
cv::namedWindow("Geo map", cv::WINDOW_NORMAL);
cv::imshow("Geo map", geoMap);
#endif
if (true)
{
double k = 0.25;
cv::Size mapPreview(cvRound(frame.cols * k), cvRound(((frame.cols * k) / geoMap.cols) * geoMap.rows));
cv::resize(geoMap, frame(cv::Rect(frame.cols - mapPreview.width - 1, frame.rows - mapPreview.height - 1, mapPreview.width, mapPreview.height)), mapPreview, 0, 0, cv::INTER_CUBIC);
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions example/CarsCounting.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ class GeoParams
cv::Point_<T> gp2(m_geoPoints[(i + 1) % m_geoPoints.size()]);
cv::Point p2(m_p2mParams.Geo2Pix(gp2));

cv::line(map, p1, p2, cv::Scalar(255, 255, 255), 1, cv::LINE_AA);
cv::line(map, p1, p2, cv::Scalar(255, 255, 255), 2, cv::LINE_AA);

//std::cout << p1 << " - " << p2 << std::endl;

std::stringstream label;
label << std::fixed << std::setw(5) << std::setprecision(5) << "[" << m_geoPoints[i].x << ", " << m_geoPoints[i].y << "]";
int baseLine = 0;
double fontScale = 0.5;
cv::Size labelSize = cv::getTextSize(label.str(), cv::FONT_HERSHEY_SIMPLEX, fontScale, 1, &baseLine);
cv::putText(map, label.str(), p1, cv::FONT_HERSHEY_SIMPLEX, fontScale, cv::Scalar(255, 255, 255));
double fontScale = (map.cols < 1000 && map.rows < 1000) ? 0.5 : 1.;
cv::Size labelSize = cv::getTextSize(label.str(), cv::FONT_HERSHEY_TRIPLEX, fontScale, 1, &baseLine);
cv::putText(map, label.str(), p1, cv::FONT_HERSHEY_TRIPLEX, fontScale, cv::Scalar(255, 255, 255));
}
#endif

Expand All @@ -189,7 +189,7 @@ class GeoParams
auto center = m_p2mParams.Geo2Pix(geoCenter);
//std::cout << "Convert: " << track.m_rrect.center << " -> " << geoCenter << " -> " << center << std::endl;
if (center.x > 0 && center.x < map.cols && center.y > 0 && center.y < map.rows)
cv::ellipse(map, center, cv::Size(3, 3), 0, 0, 360, cv::Scalar(255, 0, 255), cv::FILLED, 8);
cv::ellipse(map, center, cv::Size(5, 5), 0, 0, 360, cv::Scalar(255, 0, 255), cv::FILLED, 8);
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/VideoExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class VideoExample
bool m_isDetectorInitialized = false;
std::string m_inFile;
std::string m_outFile;
int m_fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
int m_fourcc = cv::VideoWriter::fourcc('h', '2', '6', '5'); //cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
int m_startFrame = 0;
int m_endFrame = 0;
int m_finishDelay = 0;
Expand Down

0 comments on commit 51b8386

Please sign in to comment.