bounding box的提取

#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;
  
 }//input.close();
  /*for (int i = 0; i < 68; i++) {
   cout << points[i].x << "  " << points[i].y << endl; 
   circle(image, points[i], 3, Scalar(0, 0, 255), CV_FILLED, CV_AA);
  }
 
  imshow("landmark", image);
  waitKey();*/
 file_out1.close();
 file_out2.close();
 cin.get();
 return 0;
}

猜你喜欢

转载自blog.csdn.net/d324394095/article/details/80356404
今日推荐