首页 文章

openCV for android face recognition显示“mat not continuous”错误

提问于
浏览
0

我试图在openCV for Android中将图像加载到Mat中以进行面部识别 .

图像采用尺寸为640 x 480的jpeg格式 .

我正在使用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:reshape(int,int)const”中更改

我尝试在OpenCV 2.0 C++ API using imshow: returns unhandled exception and "bad-flag"中使用该解决方案

但它在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();

1 回答

  • 2

    “Mat not continuous”错误与您在那里的链接完全没有关系 .

    如果你正在尝试渔夫或特征脸,那么这些图像必须被“压扁”为pca的单行 . 这是不可能的,如果数据有“间隙”或填充以使行大小为4的倍数 . 一些图像编辑器对您的数据执行此操作 .

    另外,imho你的图像太大了(当它几乎是二次时,pca效果最好,即rowsize(num_pixels)类似于colsize(num_images) .

    因此我的建议是,将火车图像(以及后面的测试图像)调整为100x100之类的大小,加载它们时,这也将实现连续的数据块 .

    (再次,避免jpegs与任何图像处理相关,太多的压缩文物!)

相关问题