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);