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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:13:06+00:00 2026-06-12T04:13:06+00:00

I need to read an image with OpenCV, get its size and send it

  • 0

I need to read an image with OpenCV, get its size and send it to a server so it processes the image and give it back to me the extracted features.

I have been thinking of using a vector<byte>, but I don’t understand how to copy the data to a cv::Mat. I wan’t it to be fast so I am trying to access the data with a pointer but I have a runtime exception. I have something like this.

Mat image = imread((path + "name.jpg"), 0);
vector<byte> v_char;
for(int i = 0; i < image.rows; i++)
    {   
        for(int j = 0; j < image.cols; j++)
        {
            v_char.push_back(*(uchar*)(image.data+ i + j));             

        }           
    }
  • Which is the best approach for this task?
  • 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-12T04:13:07+00:00Added an answer on June 12, 2026 at 4:13 am

    Direct access is a good idea as it is the fastest for OpenCV, but you are missing the step and that is probably the reason why your program breaks. The next line is wrong:

    v_char.push_back(*(uchar*)(image.data+ i + j)); 
    

    You don’t have to increment i, you have to increment i + image.step. It will be this way:

    Mat image = imread((path + "name.jpg"), 0);
    vector<byte> v_char;
    for(int i = 0; i < image.rows; i++)
        {   
            for(int j = 0; j < image.cols; j++)
            {
                v_char.push_back(*(uchar*)(image.data+ i*image.step + j));             
    
            }           
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read binary PGM image files. Its format: P5 # comments nrows
I have very little Perl experience. I need to read a binary image in
This plugin reads image files on blueimproot/server/php/files on page load. I need to read
Actually in one of my project i need to read images from remote server
I need to read test.TXT file(tab delimited) into MATLAB. TXT file have form: Datum
I'm trying to display an image using OpenCV. I have the following very basic
Using php I need to read an image to a byte stream which has
I want to display an image in graphics mode. I have read the image
What I need is to construct a intensity grid(image) in OpenCV from which I
I have read in an image into a LPPICTURE with OleLoadPictre and displayed it

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.