这就是我现在要做的,以便从多个txt文件中读取数据。什么会是更好的方式来处理这个问题?我想将结果存储在单独的向量中(我在这里称为out1
,out2
等)。 数据包含我正在进行Hough变换的XY坐标。如何从编号的txt文件读取? (data1.txt,data2.txt等)
ifstream data1, data2, data3, data4;
vector< vector<float> > XY1, XY2, XY3, XY4;
vector<float> row1(2), row2(2), row3(2), row4(2);
vector<CircleData> out1, out2, out3, out4;
// Read data
data1.open("data1.txt");
while (data1 >> row1[0] >> row1[1])
{
XY1.push_back(row1);
}
data1.close();
// Convert XY-coordinates to pixels with image size as parameter
CoordinatesToImage convert1(XY1, 300);
// Do Hough transformation, then search for the strongest circles in the data
CircleHough test1;
out1 = test1.houghPeaks(test1.houghTransform(convert1.getScan(), radius), radius, 7);
// Next data file, same procedure
data2.open("data2.txt");
while (data2 >> row2[0] >> row2[1])
{
XY2.push_back(row2);
}
data2.close();
// Convert XY-coordinates to pixels with image size as parameter
CoordinatesToImage convert2(XY2, 300);
// Do Hough transformation, then search for the strongest circles in the data
CircleHough test2;
out2 = test2.houghPeaks(test2.houghTransform(convert2.getScan(), radius), radius, 7);
// Next data file, same procedure
data3.open("data3.txt");
......
美丽。但是,在'read_and_process_file_input(“data”+ i +“.txt”);'时出现错误。 “表达式必须具有整数或无限范围的枚举类型”。我试着用一个字符串代替,并将''data“+ i +”.txt“'转换为字符串,但这并不起作用。 – asdfghjkl
是的,有一个语法错误(+符号不适用于C原始字符*)。尝试使用std :: string,你是否改变了参数定义(char * filename) - >(std :: string filename)? – cadaei
是的,我做到了。但是,我没有确定我的路径是哪个问题。非常感谢你!它现在有效 – asdfghjkl