Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

read 2d array into opencv mat

i need to read dynamic two dimensional array in opencv mat

int main()
{
Mat matrix;
double **theArray;
int numOfRows,numOfCols;

cin >> numOfRows ;
cin >> numOfCols ;

theArray = AllocateDynamicArray<double>(numOfRows,numOfCols);

matrix = Mat(numOfRows,numOfCols,CV_64FC1,&theArray);

string filename = "IN.xml";
FileStorage fs1(filename, FileStorage::WRITE);
fs1.open(filename, FileStorage::WRITE);
fs1 << "locsINMat"          << matrix;  
fs1 << "descriptorsINMat"   << matrix;
fs1.release();
cout << "---------------------" << endl;

FreeDynamicArray(theArray);

}
template <typename T> 
T **AllocateDynamicArray( int nRows, int nCols)
{
      T **dynamicArray;

      dynamicArray = new T*[nRows];
      for( int i = 0 ; i < nRows ; i++ )
      dynamicArray[i] = new T [nCols];

      return dynamicArray;
}

template <typename T>
void FreeDynamicArray(T** dArray)
{
      delete [] *dArray;
      delete [] dArray;
}

i get this exception: Unhandled exception at 0x5d08f1aa in GP.exe: 0xC0000005: Access violation reading location 0x003f4000.