0

我正在使用 c++ 和 opencv lib 编写一个程序,我需要将数据存储在一个地方以方便临时(这样我就可以在不移动太多的情况下访问信息)而不是写入文件。

所以我想创建一个包含多个对象的向量(如 2 个 cv::Point3f 对象)和原子数据类型(int、int、float、Boolean)

这是否可以创建这些对象和原始类型的向量的向量?如果是,我该怎么做?如果没有,还有什么其他选择?

4

2 回答 2

1

我找到了解决方案。有兴趣的人:

#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <iostream>
#include <vector>

#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>

int main()
{

    std::vector < boost::tuple <CvPoint3D32f, CvPoint3D32f, int, int, float, bool> > test12;

    test12.push_back(boost::make_tuple(cvPoint3D32f(2.0, 3.0, 1.2), cvPoint3D32f(2.5, 7.0, 5.2), 5, 1, 6.0, true));

    std::cout << boost::get<0>(test12[0]).z << std::endl;

    return 0;

 }
于 2012-05-30T05:14:38.737 回答
1

这是否可以创建这些对象和原始类型的向量的向量?如果是,我该怎么做?

是的,可以有向量的向量,例如:

  // Vector length of 3 initialized to 0
   vector<int> myMatrix(3,0);

   // Vector length of 4 initialized to hold another
   // vector myMatrix which has been initialized to 0
   vector< vector<int> > myMatrix2(4, myMatrix);

   // Vector of length 5 containing two dimensional vectors
   vector< vector< vector<int> > > myMatrix3(5, myMatrix2);
于 2012-05-30T02:44:22.413 回答