From b3986768ad1cd7048d6bf6d972bf70d046ff667e Mon Sep 17 00:00:00 2001 From: Federico Giaimo Date: Tue, 28 Jul 2015 00:14:08 +0200 Subject: [PATCH 1/2] Overlay and console output enabled. Logging command option added. --- CaroloCup-CameraPlayback.cpp | 120 ++++++++++++++++++++++++++++++++--- 1 file changed, 111 insertions(+), 9 deletions(-) diff --git a/CaroloCup-CameraPlayback.cpp b/CaroloCup-CameraPlayback.cpp index dc5b477..86daedb 100644 --- a/CaroloCup-CameraPlayback.cpp +++ b/CaroloCup-CameraPlayback.cpp @@ -46,15 +46,76 @@ using namespace core::io; using namespace core::wrapper; using namespace tools::player; -int32_t main(int32_t argc, char **argv) { +class CSVRow +{ + public: + string const& operator[](size_t index) const + { + return m_data[index]; + } + size_t size() const + { + return m_data.size(); + } + void readNextRow(istream& str) + { + string line; + getline(str,line); + + stringstream lineStream(line); + string cell; + + m_data.clear(); + while(getline(lineStream,cell,',')) + { + m_data.push_back(cell); + } + } + private: + vector m_data; +}; + +void setLabel(cv::Mat& img, const string label, const cv::Point& anchor) +{ + int fontface = cv::FONT_HERSHEY_COMPLEX; + double scale = 0.4; + int thickness = 1; + int baseline = 0; + + cv::Size text = cv::getTextSize(label, fontface, scale, thickness, &baseline); + cv::rectangle(img, anchor + cv::Point(0, baseline), anchor + cv::Point(text.width, -text.height), CV_RGB(0,0,0), CV_FILLED); + cv::putText(img, label, anchor, fontface, scale, CV_RGB(255, 255, 255), thickness, CV_AA); +} + +void errorMessage(string name) +{ + cerr << "Wrong command line parameters supplied." << endl + << "Usage :\t" << name << " [-l] myRecording.rec [myRecording.csv]" << endl + << "Options :" << endl << " -l \t\t\t Enables logging on standard output" << endl; +} + +int32_t main(int32_t argc, char **argv) +{ uint32_t retVal = 0; - if (argc != 2) { - cerr << "Insufficient command line parameters supplied. Use " << string(argv[0]) << " myRecording.rec" << endl; + int recIndex=1; + bool log=false; + + if((argc != 2 && argc != 3 && argc != 4) || (argc==4 && string(argv[1]).compare("-l")!=0)) + { + errorMessage(string(argv[0])); retVal = 1; } - else { + else + { + // if -l option is set + if(argc==4 || (argc==3 && string(argv[1]).compare("-l")==0)) + { + ++recIndex; + log=true; + } + // Use command line parameter as file for playback; - string recordingFile(argv[1]); + string recordingFile(argv[recIndex]); stringstream recordingFileUrl; recordingFileUrl << "file://" << recordingFile; @@ -93,6 +154,17 @@ int32_t main(int32_t argc, char **argv) { // also having convenient automated system resource management. SharedPointer sharedImageMemory; + ifstream file(argv[recIndex+1]); + CSVRow row; + // read out the header row + row.readNextRow(file); + uint32_t frameNumber=1, csvFN; + int32_t VPx,VPy; + stringstream frameMessage; + stringstream VPMessage; + frameMessage.str(string()); + VPMessage.str(string()); + // Main data processing loop. while (player.hasMoreData()) { // Read next entry from recording. @@ -126,15 +198,45 @@ int32_t main(int32_t argc, char **argv) { } sharedImageMemory->unlock(); - + // Show the image using OpenCV. - cvShowImage("CaroloCup-CameraPlayback", image); + + // if csv parameter is set + if(argc==4 || (argc==3 && string(argv[1]).compare("-l")!=0)) + { + row.readNextRow(file); + sscanf(row[0].c_str(), "%d", &csvFN); + if(frameNumber==csvFN) + { + cv::Mat img = cv::cvarrToMat(image); + + + frameMessage.str(string()); + VPMessage.str(string()); + sscanf(row[9].c_str(), "%d", &VPx); + sscanf(row[10].c_str(), "%d", &VPy); + + frameMessage<<"Frame "<(c) == 27) break; + if (static_cast(c) == 27) break; + + ++frameNumber; } } } From c6b5c914c0513871aec5f1274e9df98a4bbf5150 Mon Sep 17 00:00:00 2001 From: fgiaimo Date: Tue, 28 Jul 2015 12:30:09 +0200 Subject: [PATCH 2/2] Print support points and lines --- CaroloCup-CameraPlayback.cpp | 67 +++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/CaroloCup-CameraPlayback.cpp b/CaroloCup-CameraPlayback.cpp index 86daedb..1fca7ce 100644 --- a/CaroloCup-CameraPlayback.cpp +++ b/CaroloCup-CameraPlayback.cpp @@ -45,46 +45,48 @@ using namespace core::data::image; using namespace core::io; using namespace core::wrapper; using namespace tools::player; +using namespace cv; class CSVRow { public: - string const& operator[](size_t index) const + string const& operator[](uint32_t index) const { return m_data[index]; } - size_t size() const + uint32_t size() const { return m_data.size(); } - void readNextRow(istream& str) + bool readNextRow(istream& in) { - string line; - getline(str,line); - - stringstream lineStream(line); - string cell; + string line; + if(!getline(in,line)) return false; + + stringstream lineStream(line); + string cell; m_data.clear(); while(getline(lineStream,cell,',')) { m_data.push_back(cell); } + return true; } private: vector m_data; }; -void setLabel(cv::Mat& img, const string label, const cv::Point& anchor) +void setLabel(Mat& img, const string label, const Point& anchor) { - int fontface = cv::FONT_HERSHEY_COMPLEX; + int fontface = FONT_HERSHEY_COMPLEX; double scale = 0.4; int thickness = 1; int baseline = 0; - cv::Size text = cv::getTextSize(label, fontface, scale, thickness, &baseline); - cv::rectangle(img, anchor + cv::Point(0, baseline), anchor + cv::Point(text.width, -text.height), CV_RGB(0,0,0), CV_FILLED); - cv::putText(img, label, anchor, fontface, scale, CV_RGB(255, 255, 255), thickness, CV_AA); + Size text = getTextSize(label, fontface, scale, thickness, &baseline); + rectangle(img, anchor + Point(0, baseline), anchor + Point(text.width, -text.height), CV_RGB(0,0,0), CV_FILLED); + putText(img, label, anchor, fontface, scale, CV_RGB(255, 255, 255), thickness, CV_AA); } void errorMessage(string name) @@ -159,7 +161,7 @@ int32_t main(int32_t argc, char **argv) // read out the header row row.readNextRow(file); uint32_t frameNumber=1, csvFN; - int32_t VPx,VPy; + int32_t VPx,VPy,BLx,BLy,BRx,BRy,TLx,TLy,TRx,TRy; stringstream frameMessage; stringstream VPMessage; frameMessage.str(string()); @@ -204,11 +206,15 @@ int32_t main(int32_t argc, char **argv) // if csv parameter is set if(argc==4 || (argc==3 && string(argv[1]).compare("-l")!=0)) { - row.readNextRow(file); + if(! row.readNextRow(file)) break; + while(row[0].compare("")==0) + if(! row.readNextRow(file)) break; + sscanf(row[0].c_str(), "%d", &csvFN); + if(frameNumber==csvFN) { - cv::Mat img = cv::cvarrToMat(image); + Mat img = cvarrToMat(image); frameMessage.str(string()); @@ -225,6 +231,33 @@ int32_t main(int32_t argc, char **argv) if(log) cout << frameMessage.str() << " :: " << VPMessage.str() <(TLy-BLy)/static_cast(TLx-BLx); + double slope2 = static_cast(TRy-BRy)/static_cast(TRx-BRx); + Point p1(0,0), q1(img.cols,img.rows); + Point p2(0,0), q2(img.cols,img.rows); + p1.y = -(BLx-p1.x) * slope1 + BLy; + q1.y = -(TLx-q1.x) * slope1 + TLy; + p2.y = -(BRx-p2.x) * slope2 + BRy; + q2.y = -(TRx-q2.x) * slope2 + TRy; + + line(img,p1,q1,CV_RGB(255, 255, 255),1,CV_AA); + line(img,p2,q2,CV_RGB(255, 255, 255),1,CV_AA); + imshow("CaroloCup-CameraPlayback", img); } } @@ -241,6 +274,8 @@ int32_t main(int32_t argc, char **argv) } } + // maybe print EOF message && wait for user input? + // Release IplImage data structure. cvReleaseImage(&image);