OPENCV中给定矩阵的形状错误 [英] Wrong shapes for given matrices in OPENCV

查看:176
本文介绍了OPENCV中给定矩阵的形状错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用opencv执行面部识别.为此,训练图像和测试图像必须具有相同的大小. 所以我用了这个功能:

I am trying to perform facial recogntion using opencv. For this the training and test images have to be of the same size. So I used this function:

resize(testing,output, images[0].size(),0,0,INTER_NEAREST);

其中测试是来自网络摄像头的Mat,输出是调整大小的图像,images [0] .size()是我的矢量图像数据库. 但是我收到以下错误:

Where testing is my Mat from the webcam , Output is the resized image , images[0].size() is my database of vector images. However I get the following error:

OpenCV Error: Bad argument (Wrong shapes for given matrices. Was size(src) = (1,921600), 
size(W) = (307200,6).) in subspaceProject,
file /home/someplae/OpenCV-2.4.2/modules/contrib/src/lda.cpp, 
line 187
terminate called after throwing an instance of 'cv::Exception'
what():  /home/someplace/OpenCV-2.4.2/modules/contrib/src/lda.cpp:187: 
error: (-5) Wrong shapes for given matrices. Was size(src) = (1,921600), size(W) = (307200,6). 
in function subspaceProject

推荐答案

尽管您没有提供足够的代码来进行验证,但是我可以从给定的元素数量中推断出该问题.您的测试矩阵是921600 = 3 * 307200 ...所以我想您的输入矩阵不是灰度矩阵,但仍然是BGR表示形式.

Although you don't provide enough code to verify, I can infer the problem from the given number of elements. Your test matrix is 921600 = 3 * 307200... So I guess your input matrix is not a grayscale matrix, but still is in BGR representation.

您应该使用

You should use cv::cvtColor to convert the matrix to grayscale, before resizing it:

这篇关于OPENCV中给定矩阵的形状错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆