c++向量问题;通过引用传递东西

发布于 2024-11-08 20:31:55 字数 1783 浏览 0 评论 0原文

所以我检查了我的指针,我真的不确定这里出了什么问题。我通过引用修改它们的函数来传递两个向量。这是函数:

bool imageToTips( Mat& img,
  vector<vector<int> > & fingertips,
  vector<vector<Point> > & hand,
  double epsilon,
  double theta){
      //code 
}

这里是它的调用位置:

Mat depth = _depth;
Mat image = depth.clone();
Mat decon = depth.clone();
vector<vector<int> >  fingertips();
vector<vector<Point> >  hands();
double epsilon = 50;
double theta = 30;
if (fs::imageToTips(decon, fingertips, hands, epsilon, theta)) 
{
    drawContours(image, hands, -1, Scalar(255,0,0,0));
    imshow("KinectFingerProcessing", image);
    //more code
}

错误:

/FingerLocator2/main.cpp:47: error: invalid initialization of non-const reference of type 'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&' from a temporary of type 'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > (*)()'

/FingerLocator2/main.cpp:49: error: invalid initialization of reference of type 'const std::vector<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >, std::allocator<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > > > >&' from expression of type 'std::vector<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >, std::allocator<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > > > > (*)()'

我尝试过创建向量指针,但没有成功。我想我在某个地方使用了临时变量……这里出了什么问题?

So I've checked my pointers and I'm really not sure what's going wrong here. I'm passing 2 vectors of vectors by reference to a function that modifies them. Here's the function:

bool imageToTips( Mat& img,
  vector<vector<int> > & fingertips,
  vector<vector<Point> > & hand,
  double epsilon,
  double theta){
      //code 
}

And here's where it's called:

Mat depth = _depth;
Mat image = depth.clone();
Mat decon = depth.clone();
vector<vector<int> >  fingertips();
vector<vector<Point> >  hands();
double epsilon = 50;
double theta = 30;
if (fs::imageToTips(decon, fingertips, hands, epsilon, theta)) 
{
    drawContours(image, hands, -1, Scalar(255,0,0,0));
    imshow("KinectFingerProcessing", image);
    //more code
}

The errors:

/FingerLocator2/main.cpp:47: error: invalid initialization of non-const reference of type 'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&' from a temporary of type 'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > (*)()'

/FingerLocator2/main.cpp:49: error: invalid initialization of reference of type 'const std::vector<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >, std::allocator<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > > > >&' from expression of type 'std::vector<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >, std::allocator<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > > > > (*)()'

I've tried making the vector pointers and it hasn't worked. I think I'm using a temp variable somewhere or something… what's wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里°也失望 2024-11-15 20:31:55

您不需要 () 来默认构造变量,否则您将定义一个函数。

vector<vector<int> >  fingertips;
vector<vector<Point> >  hands;
//                           ^ loose the ()s

You don't need the () to default-construct a variable, otherwise you're defining a function.

vector<vector<int> >  fingertips;
vector<vector<Point> >  hands;
//                           ^ loose the ()s
夏见 2024-11-15 20:31:55

您应该像这样初始化向量,不带“()”:

vector<vector<int> >  fingertips;
vector<vector<Point> >  hands;

You should be initializing the vectors like this, without the '()':

vector<vector<int> >  fingertips;
vector<vector<Point> >  hands;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文