2

Hi I am using OpenCV to prepare a GLCM work, but an error occurred. I am using Qt 5.4.2 MSVC 2013 - 32 bit

Starting C:\Workspace\QtProjects\build-iRov-Desktop_Qt_5_4_2_MSVC2013_64bit-Debug\debug\iRov.exe...

OpenCV Error: Insufficient memory (Failed to allocate 1012712448 bytes) in cv::OutOfMemoryError, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\alloc.cpp, line 52 OpenCV Error: Assertion failed (u != 0) in cv::Mat::create, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line 411

***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****

This is my code:

#include <QApplication>
#include <QImage>
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "iostream"
#include <string>

using namespace cv;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    //IRovForm w;
   // w.showMaximized();

    int intensidadeMaxima, intensidadeMinima = 0;
    Mat img(50,50,CV_8UC1, Scalar::all(0));
    for(int i = 0;i< img.rows;i++){
        for(int j = 0;j< img.cols;j++){
            if(i>10 && i < 30 && j > 10 && j < 30)
            {
                 img.at<uchar>(i,j) = 255;
            }

        }
    }
    //resgata a intensidade de maior valor para criar a matriz de coocorrencia. Matriz quadrada
    for(int i = 0;i< img.rows;i++){
        for(int j = 0;j< img.cols;j++){
           if(img.at<uchar>(i,j) > intensidadeMaxima)
               intensidadeMaxima = img.at<uchar>(i,j);
        }
    }
    Mat GLCM_0 = Mat::zeros(intensidadeMaxima,intensidadeMaxima, CV_8UC1);
    Mat GLCM_45 = Mat::zeros(intensidadeMaxima,intensidadeMaxima, CV_8UC1);
    Mat GLCM_90 = Mat::zeros(intensidadeMaxima,intensidadeMaxima, CV_8UC1);
    Mat GLCM_135 = Mat::zeros(intensidadeMaxima,intensidadeMaxima, CV_8UC1);
    imshow("teste",img);
    return a.exec();
}
Tonechas
  • 13,398
  • 16
  • 46
  • 80
  • You're trying to allocate a 1 gigabyte chunk of address space. This can fail. It seems that you're confused as to whether you compile for 32 or 64 bits. Judging by the shadow build folder name, you are in fact compiling for 64 bits. – Kuba hasn't forgotten Monica Aug 27 '15 at 17:43
  • You're allocating too big matrices. Your Qt is compiled also 64 bit, btw. – Miki Aug 27 '15 at 20:17
  • With such high numbers of rows and cols, probably most of them would be 0. Try with SparseMat. – Miki Aug 27 '15 at 20:20

0 Answers0