0
votes

I am trying to load images into a Mat in openCV for Android for face recognition.

The images are in in jpeg format of size 640 x 480.

I am using Eclipse and this codes are in .cpp file.

This is my codes.

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()));

        }
    }

However, I am getting an error saying that "The matrix is not continuous, thus its number of rows cannot be changed in function cv::Mat cv:Mat:reshape(int,int)const"

I tried using the solution in OpenCV 2.0 C++ API using imshow: returns unhandled exception and "bad-flag"

but it's in Visual Studio.

Any help would be greatly appreciated.

Conversion of image from Camera preview.

The image is converted to Grayscale from camera preview data.

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);

Saving image.

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmFace[0].compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] flippedImageByteArray = stream.toByteArray();
1
Do you sure the error was caused by your code pasted above? And this answer by the developer may be helpful.Yantao Xie

1 Answers

2
votes

the 'Mat not continuous' error is not at all related to the link you have there.

if you're trying fisher or eigenfaces, the images have to get 'flattened' to a single row for the pca. this is not possible, if the data has 'gaps' or was padded to make the row size a multiple of 4. some image editors do that to your data.

also, imho your images are by far too large ( pca works best, when it'S almost quadratic, ie the rowsize (num_pixels) is similar to the colsize(num_images).

so my proposal would be, to resize the train images ( and also the test images later ) to something like 100x100, when loading them, this will also achieve a continuous data block.

(and again, avoid jpegs for anything image-processing related, too many compression artefacts!)