bounding box的提取

本文介绍了一个使用C++编写的图像坐标标注程序,该程序能够从指定路径读取图像及其对应的面部特征点文件,并在此基础上进行坐标偏移处理,最终将原始坐标及偏移后的坐标分别保存到两个不同的文件中。
#include <iostream> 
#include <fstream> 
#include <opencv2/opencv.hpp>
#define random(x) (rand()%x)
using namespace std;
using namespace cv;
int main()
{
 string Imagedir = "D:/300-w data/300W1/01_Indoor/indoor_001.png";
 Mat image = imread(Imagedir, -1);    //读取原图 
 
 
 ofstream file_out1;
 ofstream file_out2;
 file_out1.open("D:/300-w data/300W1/stan.txt", std::ios::out | std::ios::app);
 file_out2.open("D:/300-w data/300W1/nois.txt", std::ios::out | std::ios::app);
 char dir[50];
 if (!file_out1.is_open() && !file_out2.is_open())
    return 0;
 for (int j = 1; j < 301; j++)
 { if (j <10){
   sprintf(dir, "%s%d%s", "D:/300-w data/300W1/01_Indoor/indoor_00", j, ".pts");
   
 }
 else if (j >= 10 && j<100 ){
   sprintf(dir, "%s%d%s", "D:/300-w data/300W1/01_Indoor/indoor_0", j, ".pts");
   //cout << dir << endl;
 }
 else if (j>=100){
   sprintf(dir, "%s%d%s", "D:/300-w data/300W1/01_Indoor/indoor_", j, ".pts");
 }
  ifstream input;
  input.open(dir);
  string s;
  for (int k = 0; k < 3; k++) {    //前三行 
   getline(input, s);
   //cout << s << endl;
  }
  vector<Point2f> points;
  Point2f point;
  for (int i = 0; i < 68; i++) {
   input >> point.x >> point.y;
   //cout << point.x << " " << point.y << endl;
  
   points.push_back(point);
  }
  float xmax=0.0, ymax=0.0,xmin=4000.0,ymin=4000.0;
  float xmax_n, ymax_n, xmin_n, ymin_n;
  for (int i = 0; i < 68; i++){
   if (xmax < points[i].x)
    xmax = points[i].x;
  }
  //cout << xmax << endl;
  for (int i = 0; i < 68;i++){
   if (ymax < points[i].y)
    ymax = points[i].y;
  }
  //cout << ymax << endl;
  for (int i = 0; i < 68; i++){
   if (xmin >= points[i].x)
    xmin = points[i].x;
  }
  //cout << xmin << endl;
  for (int i = 0; i < 68; i++){
   //cout << points[i].y << endl;
   if (ymin >= points[i].y)
    ymin = points[i].y;
  }
  //cout << ymin << endl;
  xmax_n = xmax + random(100)-50;
  ymax_n = ymax + random(100)-50;
  xmin_n = xmin + random(100)-50;
  ymin_n = ymin + random(100)-50;
  file_out1 << xmin << " " << ymin<< " " << ymax << " " << ymax << endl;
  file_out2 << xmin_n << " " << ymin_n << " " << xmax_n << " " << ymax_n << endl;
  
 }
 file_out1.close();
 file_out2.close();
 cin.get();
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值