转化标签格式

xiaoxiao2021-02-28  118

将x,y,w,h.转换成x1,y1,x2,y2

#include<opencv2/opencv.hpp> #include <iostream> #include <vector> #include <fstream> #include <string> using namespace cv; using namespace std; int main() { fstream fout("../out.txt", ios::out); ifstream infile("../label.txt"); std::vector<string> imgnames; std::vector<vector<int>> rois; while (1) { string imgname; infile >> imgname; imgnames.push_back(imgname); if (imgname.empty()) break; std::vector<int> roi; int label; for (int i = 0; i < 4; i++) { infile >> label; roi.push_back(label); } rois.push_back(roi); } for (int i = 0; i < rois.size(); i++) { fout << imgnames[i] << " "; for (int j = 0; j < 4; j++) { if (j == 2) rois[i][j] = rois[i][j] + rois[i][j - 2]; if (j == 3) rois[i][j] = rois[i][j] + rois[i][j - 2]; fout << rois[i][j]<<" "; } fout << endl; } fout.close(); return 0; }

转载请注明原文地址: https://www.6miu.com/read-41957.html

最新回复(0)