尝试从深度图像中提取手部轮廓时出现无效矩阵错误
Invalid matrix error when trying to extract hand contours from a depth image
我使用OpenCV和OpenNI一起提取手,然后从Xtion传感器生成的深度图像中提取单个手指。当手部生成器的焦点手势被执行时,hasHand bool被设置为true,并运行下面的代码。hand[]是一个浮点数组,其中跟踪手的x, y和z坐标。
if(hasHand)
{
unsigned char shade = 255 - (unsigned char)(hand[2] * 128.0f);
Scalar color(0, shade, 0);
vector<Point> handContour;
getHandContour(depthMat, hand, handContour);
bool grasp = convexity(handContour) > grabConvexity; //PROBLEM
int thickness = grasp ? CV_FILLED : 3;
circle(depthMatBgr, Point(hand[0], hand[1]), 10, color, thickness);
vector<Point> fingerTips;
detectFingerTips(handContour, fingerTips, &depthMatBgr);
}
一切运行正常,直到我注释的那一行,这时我收到:
OpenCV Error: Bad argument (input array is not a valid matrix) in unknown function, ...
我已经被这个问题困住了一段时间了,我不知道为什么我得到这个。getHandContour的代码是:
bool getHandContour(const Mat &depthMat, const float *v, vector<Point> &handContour)
{
const int maxHandRadius = 128; // in px
const short handDepthRange = 200; // in mm
const double epsilon = 17.5; // approximation accuracy (maximum distance between the original hand contour and its approximation)
depth = v[2] * 1000.0f; // hand depth
nearClip = depth - 100; // near clipping plane
farClip = depth + 100; // far clipping plane
static Mat mask(frameSize, CV_8UC1);
mask.setTo(0);
// extract hand region
circle(mask, Point(v[0], v[1]), maxHandRadius, 255, CV_FILLED);
mask = mask & depthMat > nearClip & depthMat < farClip;
// DEBUG(show mask)
imshow("mask1", mask);
// assume largest contour in hand region to be the hand contour
vector<vector<Point> > contours;
findContours(mask, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
int n = contours.size();
int maxI = -1;
int maxSize = -1;
for (int i=0; i<n; i++) {
int size = contours[i].size();
if (size > maxSize) {
maxSize = size;
maxI = i;
}
}
bool handContourFound = (maxI >= 0);
if (handContourFound) {
approxPolyDP( Mat(contours[maxI]), handContour, epsilon, true );
}
return maxI >= 0;
}
我不确定这些信息是否足以让人们帮助我(对很多人来说都是新手),但如果有任何正确的提示,我将非常感激。
编辑:对不起,我忘了在这个问题中包括convexity()代码:
double convexity(const vector<Point> &contour) {
Mat contourMat(contour);
vector<int> hull;
convexHull(contourMat, hull);
int n = hull.size();
vector<Point> hullContour;
for (int i=0; i<n; i++) {
hullContour.push_back(contour[hull[i]]);
}
Mat hullContourMat(hullContour);
return (contourArea(contourMat) / contourArea(hullContourMat));
}
我相信约xpolydp只需要一个国家,而你试图传递整个列表
相关文章:
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- what(): basic_string::_M_construct 空无效错误
- C++ Linux 运行时basic_string::_M_construct null 无效错误
- 调用boost v1.58中的函数时出现模板名称使用无效错误
- 对象分配-成员函数的使用无效错误
- 从 WindowsAPI 调用 NetLocalGroupAddMembers 时,安全 ID 结构无效错误
- 为什么映射迭代器显示基本操作数无效错误
- 获取数组类型的无效错误
- 调用 vector.erase() 函数时指针操作无效错误
- C++:basic_string::_M_construct 空,对于图形 BFS 算法无效错误
- C++运行程序后给我 basic_string::_S_construct null 无效错误
- 使用 std::vector 时抽象类类型"Shape"的新表达式无效错误
- mmap 错误:分段错误/指针无效错误
- 从字符到字符编译器的转换无效错误
- 恒常性添加无效?错误:无法使用字符**初始化常量字符**
- 二进制表达式的操作数无效错误消息
- "从'文件* {aka _iobuf}'到'int'的转换无效"错误
- 在 boost 中序列化二进制数据失败,并出现"签名无效"错误
- 基类 T 无效错误
- 从“常量字符*”到“字符*”的转换无效错误