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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:15:47+00:00 2026-05-27T02:15:47+00:00

When iterating through a cv::Mat to output all of its values, you could do

  • 0

When iterating through a cv::Mat to output all of its values, you could do the following:

for (int r = 0; r < t.rows; r++)
{
    for (int c = 0; c < t.cols; c++)
    {
        std::cout << t.at<float>(r,c) << ", ";
    }
    std::cout << std::endl << std::endl;
}

However, if the information stored in that array is not of type float, this will crash. How do you enforce the type of this matrix?

  • 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-27T02:15:48+00:00Added an answer on May 27, 2026 at 2:15 am

    for 2 Mats nonFloatMat and floatMat when the first is the source matrix and the last is the destination matrix do

    nonFloatMat.convertTo(floatMat, CV_32F); //if its a color image use CV_32FC3, or 
                                             // CV_32FC4 if its RGBA
    

    convertTo‘s reference can be found here.

    Edit:

    and by the way, the code will work if you’ll change the float to the correct concrete type of the matrix ie if the mat is a CV_8U you can do t.at<char>(r,c) etc.

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

Sidebar

Related Questions

I am iterating through the command output in a for loop. Consider the following
I'm iterating through all the types in GAC, GAC_32 and GAC_MSIL looking for specific
I'm iterating through an array and sorting it by values into days of the
I am iterating through the object and initializing all the properties of that object.
I am iterating through rows,and looking up the first column of each row(name) using
While iterating through a std::map or std::vector or any container which has iterator in
So I'm iterating through all the checked items in the box like this: for
iterating through a View's components the following code works: if (child.getClass() == EditText.class) {
Possible Duplicate: C# Iterating through an enum? (Indexing a System.Array) All I want to
Is it possible to read custom attribute value without iterating through all list of

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.