用于安卓人脸识别的 openCV 显示"mat not continuous"错误



我正在尝试将图像加载到openCV for Android的Mat中进行人脸识别。

这些图像采用jpeg格式,大小为640 x 480。

我使用的是Eclipse,这些代码在.cpp文件中。

这是我的密码。

while (getline(file, line)) {
        stringstream liness(line);
        getline(liness, path, ',');
        getline(liness, classlabel);
        if(!path.empty() && !classlabel.empty()) {
            images.push_back(imread(path, 0));
            labels.push_back(atoi(classlabel.c_str()));
        }
    }

然而,我得到了一个错误,说"矩阵不是连续的,因此它的行数不能在函数cv::Mat cv:Mat:整形(int,int)const中更改"

我尝试在OpenCV 2.0 C++API中使用imshow的解决方案:返回未处理的异常;坏标志";

但它在Visual Studio中。

如有任何帮助,我们将不胜感激。

从相机预览转换图像。

图像将从相机预览数据转换为灰度。

Mat matRgb = new Mat();
Imgproc.cvtColor(matYuv, matRgb, Imgproc.COLOR_YUV420sp2RGB, 4);
try{
Mat matGray = new Mat();
Imgproc.cvtColor(matRgb, matGray, Imgproc.COLOR_RGB2GRAY, 0);
resultBitmap = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);
Utils.matToBitmap(matGray, resultBitmap);

正在保存图像。

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmFace[0].compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] flippedImageByteArray = stream.toByteArray();

"Mat not continuous"错误与您的链接完全无关。

如果你在尝试fisher或本征面,图像必须被"压扁"为一行进行主成分分析。如果数据具有"间隙"或被填充以使行大小为4的倍数,则这是不可能的。一些图像编辑器会对您的数据进行这种处理。

此外,imho你的图像太大了(pca效果最好,当它几乎是二次的时,即行大小(num_pixels)与colsize(num_images)相似。

因此,我的建议是,将列车图像(以及稍后的测试图像)调整为100x100,当加载它们时,这也将实现连续的数据块。

(同样,避免任何与图像处理相关的jpegs,太多的压缩伪影!)

最新更新