Ask Your Question
0

load file in cv::rect opencv

asked 2016-10-24 06:33:36 -0600

azdoud.y gravatar image

I'm trying to compare code by plotting ground truth bounding box on images saved in a txt file in the following format

198,214,34,81
197,214,34,81
195,214,34,81
193,214,34,81
...

how can I load each line on a cv::Rect ? thank you in advance

I've tried this

  string fileName = "groundtruth_rect.txt";
  FileStorage fs;
  fs.open(fileName, FileStorage::READ);
  FileNode mr = fs[""];
  Rect r;
  r.x = (int)mr[0];
  r.y = (int)mr[1];
  r.width = (int)mr[2];
  r.height = (int)mr[3];

unfortunately i got this

Valid XML should start with '<?xml ...?>') in icvXMLParse, file C:\buildslave64\win64_amdocl\2_4_
PackSlave-win32-vc11-shared\opencv\modules\core\src\persistence.cpp, line 2252
edit retag flag offensive close merge delete

Comments

are there really only numbers and commas in your txt file ? then you cannot use cv::FileStorage (which expects valid xml/yml formatting / headers)

berak gravatar imageberak ( 2016-10-24 06:42:48 -0600 )edit

yes there is only numbers and commas

azdoud.y gravatar imageazdoud.y ( 2016-10-24 06:45:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-10-24 06:49:46 -0600

berak gravatar image

try with a std::ifstream:

#include <fstream>
using namespace std;

ifstream in("my.txt");
int x,y,w,h;
char comma; //dummy
vector<Rect> rects; // result
while ((in >> x) && (in >> comma) && 
          (in >> y) && (in >> comma) && 
          (in >> w) && (in >> comma) && 
          (in >> h)) {
      rects.push_back(Rect(x,y,w,h));
}
in.close()
edit flag offensive delete link more

Comments

1

by ifstream it's good idea thanks

azdoud.y gravatar imageazdoud.y ( 2016-10-24 07:20:35 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-10-24 06:33:36 -0600

Seen: 230 times

Last updated: Oct 24 '16