读取xml文件

#include "tinyxml.h"
#include <iostream>
#include <string>
#include <windows.h>
#include<vector>
#include<fstream>
#include<opencv2/opencv.hpp>
#include <time.h>

using namespace std;
using namespace cv;

int main()
{
    srand((unsigned)time(NULL));
    //data值全部存到out.txt里面 存的格式需要后续处理
    ofstream outfile("out.txt");
 
    //string filefullname = "D:\\openpose\\windows\\OpenPoseDemo\\image\\1.xml";        
    //const char* filepath = filefullname.c_str();;
    //TiXmlDocument doc(filepath);
    TiXmlDocument doc("D:\\openpose\\windows\\OpenPoseDemo\\image\\1.xml");
    bool loadOkay = doc.LoadFile(TIXML_DEFAULT_ENCODING);
    /*f (!loadOkay) {
        printf("Could not load test file %s. Error='%s'. Exiting.\n", filepath, doc.ErrorDesc());
        exit(1);
    }*/
    TiXmlElement* root = doc.RootElement();  
    for (TiXmlElement* elem = root->FirstChildElement(); elem != NULL; elem = elem->NextSiblingElement())
    {
        string elemName = elem->Value();                
        if (!elemName.compare("pose_0"))
        {                    
            for (TiXmlElement* pose_0elem = elem->FirstChildElement(); pose_0elem != NULL; pose_0elem = pose_0elem->NextSiblingElement())
            {
                string pose_0elemName = pose_0elem->Value();
                                                
                if (!pose_0elemName.compare("data"))
                    {
                        TiXmlNode *e = pose_0elem->FirstChild();
                        const char *expr = e->ToText()->Value();
                        char *buf = new char[strlen(expr) + 1];
                    /*    strcpy(buf, expr);
                        cout << expr << endl;*/
                        outfile << expr<<endl ;
                    }
            }
        }        
    }
    ifstream infile("out.txt");
    vector<float>datanums;
    float keys;
    while (infile >> keys)
    {
        datanums.push_back(keys);
    }

    float maxx = 0;
    float maxy = 0;
    for (int i = 0; i < datanums.size(); i++)
    {        
        if (i % 3 == 0)
        {
            if (datanums[i]>maxx)
            {
                maxx= datanums[i];
            }
        }
        if (i % 3 == 1)
        {
            if (datanums[i]>maxy)
            {
                maxy = datanums[i];
            }
        }        
    }
    float minx=maxx;
    float miny=maxy;
    for (int i = 0; i < datanums.size(); i++)
    {
        if (i % 3 == 0)
        {
            if (datanums[i]<minx)
            {
                minx = datanums[i];
            }
        }
        if (i % 3 == 1)
        {
            if (datanums[i]<miny)
            {
                miny = datanums[i];
            }
        }
    }
    Mat img = imread("D:\\openpose\\windows\\OpenPoseDemo\\image\\c_rendered.jpg");

    float a = rand() % 11 * 2;
    minx = minx -a  ;//(rand() % 11 - 5) * 1.0
    
    float b = rand() % 11 * 2;
    miny = miny - b;
    
    maxy = maxy + 40 + rand() % 11 * 2;
    float c = rand() % 11 * 2;
    maxx = maxx+rand() % 11 * 2;
    float d= rand() % 11 *2;
    cout << a << ' ' << b << ' ' << c << ' ' <<  d<<endl;
    cout << maxx << ' ' << maxy << endl;
    cout << minx << ' ' << miny << endl;
    Rect bbox(minx, miny, maxx - minx, maxy - miny);
    rectangle(img, bbox, cv::Scalar(255, 0, 0), 2);
    imshow("bbox", img);
    waitKey(0);


    outfile.close();    
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值