轉化標籤格式



將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;
	}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章