首页 > 解决方案 > 创建数组时出错:表达式必须具有常量值

问题描述

我正在研究使用 Hu Moment 提取功能识别手势的代码,从这里输入链接描述,但我在声明数组时遇到问题

int matchTheState(vector<Point> present_hand_state, vector<vector<Point > > MyContours)
{
double array[MyContours.size()];

而 的内容vector<vector<point>> MyContours是用作比较值的图像声明。

错误说:

expression must have constant value (cannot call non-constecxpr function...)
function call must have a constant value in a constant expression

标签: c++opencvvisual-c++opencv3.0

解决方案


在 C++ 中,数组边界必须是编译时常量。MyContours.size()不是编译时间常数。只需使用向量即可。

vector<double> array(MyContours.size());

推荐阅读