CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: OpenCV Matrix

  1. #1
    Join Date
    Aug 2009
    Posts
    68

    OpenCV Matrix

    Hello,

    Hopefully somebody on here is familiar with OpenCV....

    I am using OpenCV to try to create a 20 x 2 matrix, with floating point elements, and assign the first element of the matrix to 0.6. Here is what I have tried:

    int main()
    {
    CvMat mat = cvMat(20, 2, CV_32FC1);
    mat.data.fl[0] = 0.6;

    return 0;
    }

    This compiles well, but I get a runtime error of :

    "Unhandled exception at 0x0046b0fc in TestProgram.exe: 0xC0000005: Access violation writing location 0x00000000."

    It looks like it hasn't reserved space for the elements, but I would have thought this was done in the cvMat function...

    What am I doing wrong?

    Thanks!

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: OpenCV Matrix

    The cvMat function is used to convert a pre-existing block of memory into a CvMat. It has an optional 4th parameter which is a void*, that you didn't specify.

    If you want the space to be allocated for you, use cvCreateMat() instead, and don't forget to cvReleaseMat() when you're done with it.

    Alternatively, OpenCV now has a C++ interface; you can use a cv::Mat or cv::Mat_<T> instead, without the need to explicitly clean anything up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured