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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:50:17+00:00 2026-05-26T11:50:17+00:00

I read on http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html that a possible way to access the image data with

  • 0

I read on http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html that a possible way to access the image data with c++ is:

template<class T> class Image
{
  private:
  IplImage* imgp;
  public:
  Image(IplImage* img=0) {imgp=img;}
  ~Image(){imgp=0;}
  void operator=(IplImage* img) {imgp=img;}
  inline T* operator[](const int rowIndx) {
    return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));}
};

typedef struct{
  unsigned char b,g,r;
} RgbPixel;

typedef struct{
  float b,g,r;
} RgbPixelFloat;

typedef Image<RgbPixel>       RgbImage;
typedef Image<RgbPixelFloat>  RgbImageFloat;
typedef Image<unsigned char>  BwImage;
typedef Image<float>          BwImageFloat;

So I’m able to use something like:

IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);
RgbImage  imgA(img);
imgA[i][j].b = 111;
imgA[i][j].g = 111;
imgA[i][j].r = 111;

When I use:

imgA[i][j].b

My question is: how cpp knows the channels of the image? I mean, how c++ populates the

img[i][j].b as blue channel
img[i][j].g as green channel and 
img[i][j].r as red channel?

Does it have a default constructor to the structs?!

  • 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-26T11:50:17+00:00Added an answer on May 26, 2026 at 11:50 am

    You should have a look at how templates (Template metaprogramming) are working.

    You have a constructor but the rgb channels are populated in the

     inline T* operator[](const int rowIndx)
     {
        return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));
     }
    

    when you instantiate the Template with a RgbPixel structure your function will became:

     inline RgbPixel* operator[](const int rowIndx)
     {
        return ((RgbPixel *)(imgp->imageData + rowIndx*imgp->widthStep));
     }
    

    Because the data in both (the image and the RgbPixel structure) is stored in a continuous block of memory you will get the correct informations.

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

Sidebar

Related Questions

I read ( http://www.stereopsis.com/FPU.html ) mentioned in ( What is the fastest way to
I read here http://www.daniweb.com/code/snippet217293.html# it is possible. What should be activated in PHP.Ini or
I read from http://www.apple.com/iphone/specs.html that IPhone4's screen is 960-by-640-pixel resolution at 326 ppi. But
Possible Duplicate: C++ virtual function table memory cost I've juste read that : http://www.parashift.com/c++-faq-lite/virtual-functions.html
I successfully installed the menu-block module and I read on http://www.palantir.net/blog/better-know-module-menu-block-part-i that there is
I read the description of std::nth_element at http://www.sgi.com/tech/stl/nth_element.html template <class RandomAccessIterator> void nth_element(RandomAccessIterator first,
I wanted to try the example here http://www.codeconscious.com/rebol/rebol-net.html#HTTP print read/custom http://babelfish.altavista.com/translate.dyn reduce ['POST {text=REBOL+Rules&lp=en_fr}]
So, here is the discussion I have just read: http://www.mail-archive.com/delphi@delphi.org.nz/msg02315.html BeginUpdate and EndUpdate is
I've read: http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#the-accesskey-attribute and it doesn't say anywhere if or how the 'Home' key
I've just read http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html?page=5 and it says: the compiler is free to assign a

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.