Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:55:08+00:00 2026-05-27T11:55:08+00:00

I created OpenCV matrix: CvMat * src = cvCreateMat(1, 2, CV_32FC2); Then I want

  • 0

I created OpenCV matrix:

CvMat * src = cvCreateMat(1, 2, CV_32FC2);

Then I want to set up element row=0, col=1, channel=1
According to the example in description of documentation for CvMat
I tried to set element with the following code:

 CV_MAT_ELEM(*src, float, 0, 1 * 2 + 1) = 123;

But assert is fired.
And the reason is obvious:

We have following defintions in OpenCV sources:

#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size )  \
    (assert( (unsigned)(row) < (unsigned)(mat).rows &&   \
             (unsigned)(col) < (unsigned)(mat).cols ),   \
    (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))

#define CV_MAT_ELEM( mat, elemtype, row, col )           \
    (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))

In my case mat.cols == 2 and col == 1 * 2 + 1 == 3.

What is wrong: documentation or assert in sources of OpenCV?
How to manage this?
How can I set up element of multichannel matrix?
Thanks.

P.S. To OpenCV developers if anyone here.
When I press “you can create one now” to create new account to report a bug from the page http://opencv.willowgarage.com/wiki/Welcome?action=login, I obtain the error “Unknown action newaccount.”

UPDATE:

I use OpenCV 2.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:55:09+00:00Added an answer on May 27, 2026 at 11:55 am

    I have worked around usage of CV_MAT_ELEM:

    float * src_ptr = (float*)src->data.ptr;
    *(src_ptr + 1 * 2 + 1) = 123;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a c/c++ program which uses opencv library. I want to convert
I created a Rails application normally. Then created the scaffold for an event class.
I have been trying to set up OpenCV for the past few days with
I have created a new project (without code) that uses OpenCV. I the project
I am writing a Opencv C code in eclipse -Ubuntu. I created an executable
I want to use cvDrawContours to draw my own contours created from CvSeq (normally,
I am trying to create a CvMat data structure using cvMat() in OpenCV. The
In OpenCV, there is a CvSVM class which takes in a matrix of samples
I am using opencv and successfully created a video file using number of images.
I am using newer opencv library of willowgarage in eclipse. And I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.