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 8526621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:19:25+00:00 2026-06-11T08:19:25+00:00

I used the following code to access to Mat’s elements and found this difficulty:

  • 0

I used the following code to access to Mat’s elements and found this difficulty:
enter image description here

2 problems arise here:

  • nzpxl Mat is hard-defined the type CV_16UC2 or it is passed in from this function’s caller
  • nzpxl is accessed by at which is also a hard form

So, when there isn’t a good correspondence between the two, the function crashes. I hardly know which are even compatible. For example, does CV_16UC2 correspond with Vec2i ??

Question 1: Can this only be hard coded?
Question 2: How to know the compatible types?

Edit 01:
Sorry for lack of information! About Mat_ template, I’ve seen posts using Mat_ to define their own type for clarity and avoid using OpenCV default types. Is this one answer to my 2nd question?

  • 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-06-11T08:19:27+00:00Added an answer on June 11, 2026 at 8:19 am

    There is a moment where you have to decide what kind of data you are storing in your matrix, and this has to be “hard-coded” somewhere.

    If you decide that your data matrix is of type CV_16UC2, then you should check in all functions that access pixels in this matrix (e.g. using at<>) that the matrix is in the expected form:

    void someFunction(cv::Mat &myMatrixOf16UC2) {
      // using asserts
      assert(myMatrixOf16UC2.type() == CV_16UC2);
      // or using exceptions
      if (myMatrixOf16UC2.type() != CV_16UC2)
        throw  someException;
    
    
      // do the job
    

    }

    By the way, int are 32 bits, so Vec2i should deal with matrices allocated with CV_32SC2.
    CV_16UC2 -> cv::Vec2s, or even cv::Vec for which there is no predefined typedefs in OpenCV.

    One useful pratice is to define somewhere for your program the data you are using with a typedef and a corresponding type() function, e.g. in a header:

     typedef cv::Vec<unsigned short, 2> pixel_t;
    

    and

     int getOpenCVTypeForMyPixelType() { return CV_16UC2; }
    

    Then if you want to change from short to int or float, you just have to modify those functions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my C# project,I used the following code to access my form outside its
I used following code to access an image from res folder with NetBeans imgWelcome
The following code produces the error, Templates can be used only with field access,
I used following code, but it displays only 2 digit of ISO country name.
I have used following code to convert string to json and parse it. String
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
I am trying to used following code but I am not getting good performance
I've used following code snippet for my activity in order to deal with orientation
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I

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.