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

  • Home
  • SEARCH
  • 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 8064869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:29:42+00:00 2026-06-05T11:29:42+00:00

I am working with images in C++ with OpenCV. I wrote code with an

  • 0

I am working with images in C++ with OpenCV.

I wrote code with an uchar array of two dimensions where I can read pixel values of an image, uploaded with imread in grayscale using .at< uchar>(i,j).

However I would like to do the same thing for color images. Since I know that to access the pixels values I now need .at< Vec3b>(i,j)[0], .at< Vec3b>(i,j)[1] and .at< Vec3b>(i,j)[2], I made a similar Vec3b 2d arrays.

But I don’t know how to fill this array with the pixel values. It has to be a 2D array.

I tried:

array[width][height].val[0]=img.at< Vec3b>(i,j)[0]

but that didn’t work.

Didn’t find an answer on the OpenCV doc or here neither.

Anybody has an idea?

I’ve included some of my code. I need an array because I already have my whole algorithm working, using an array, for the images in grayscale with only one channel.

The grayscale code is like that:

for(int i=0;i<height;i++){
    for(int j=0;j<width;j++){
        image_data[i*width+j]=all_images[nb_image-1].at< uchar>(i,j);
    }
}

Where I read from:

std::vector< cv::Mat> all_images

each image (I have a long sequence), retrieves the pixel values in the uchar array image_data, and processes them.

I want now to do the same but for RGB images, and I can’t manage to read the data pixel of each channel and put them in an array.

This time image_data is a Vec3b array, and the code I’m trying looks like this:

for(int i=0;i<height;i++){
    for(int j=0;j<width;j++){
        image_data[0][i*width+j]=all_images[nb_image-1].at<cv::Vec3b>(i,j)[2];
        image_data[1][i*width+j]=all_images[nb_image-1].at<cv::Vec3b>(i,j)[1];
        image_data[2][i*width+j]=all_images[nb_image-1].at<cv::Vec3b>(i,j)[0];
    }
}

But this doesn’t work, so I am now at loss I don’t know how to succeed to fill the image_data array with the values of all three channels, without changing the code structure as this array is then used on my image processing algorithm.

  • 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-05T11:29:43+00:00Added an answer on June 5, 2026 at 11:29 am

    Here is the code I just tested, and it works.

    #include <iostream>
    #include <cstdlib>
    #include <opencv/cv.h>
    #include <opencv/highgui.h>
    
    int main(int argc, char**argv){
    
      cv::Mat img = cv::imread("image.jpg",1);
      cv::imshow("image",img);
      cv::waitKey(0);
      cv::Vec3b firstline[img.cols];
      for(int i=0;i<img.cols;i++){
        // access to matrix
        cv::Vec3b tmp = img.at<cv::Vec3b>(0,i);
        std::cout << (int)tmp(0) << " " << (int)tmp(1) << " " << (int)tmp(2) << std::endl;
        // access to my array
        firstline[i] = tmp;
        std::cout << (int)firstline[i](0) << " " << (int)firstline[i](0) << " " << (int)firstline[i](0) << std::endl;
      }
      return EXIT_SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this camera application that I'm working on which uses openCV for image
I'm trying to get some image processing code working in MS VC++ 2010 express.
Intro: I'm working on an image processing task trying to find two borders of
I'm currently working on Image stitching using OpenCV 2.3.1 on Visual Studio 2010, but
I wrote a simple test program for opencv to see if it's working after
I'm working on a project of image stitching using OpenCV 2.3.1 on Visual Studio
I am working with images and computing radon transform for an object. The function
There are some very useful classes for working with images. I am stuck with
I'm working with multiple images that need to be compressed using the DXT/S3TC format
I am working on a project to capture images via webcam in a predefined

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.