Ask Your Question

Why do i get this ^@ when i attempt to access the first element of a CvMat data struct member?

asked 2013-10-11 10:02:29 -0500

joeish80829 gravatar image

updated 2013-10-11 16:41:51 -0500

Moster gravatar image

when i run this code

  double a[]={1.0,2.0,3.0,4.0};
  CvMat M=cvMat(8,8,CV_8UC1, a);

to access a 1.0, the first element of the matrix, i get the output^@ oddly enough i tried copying the cout output into this ? and the ^@ wouldn't copy..i got only when i pasted...I tied other variations like[0] and but just got normal error and null output for those 2 respectively. how would i go about accessing the 1.0 by dereferencing the data struct member and not using a function i/e cvGet2D...just in case its emacs thats doing this i thought id report im using Emacs on Ubuntu Saucy...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-11 16:38:23 -0500

Moster gravatar image

updated 2013-10-11 16:39:09 -0500

First I want to say that the c style cvMat is deprecated and wont be supported in the future, maybe even removed.

Anyways, you are basically doing 2 mistakes. You are creating a Mat of type uchar, but your data is a double array, and you are trying to access the cvMat in a wrong way for your data type.

correct initialization:

double a[]={1.0,2.0,3.0,4.0};
CvMat M=cvMat(8,8,CV_64FC1, a);

To access the data:


Looking at the data union would have helped in this case.

    uchar* ptr;
    short* s;
    int* i;
    float* fl;
    double* db;
} data;
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-10-11 10:02:29 -0500

Seen: 83 times

Last updated: Oct 13 '13