hi friends,

i am doing visual c++ course , i got a image which captured from webcam, that image to be stored in 2d array can any one help me how to store that RGB image in to an array please.

Post some code of what you have so far please.

//image.h
struct RGB
{
    int Red;
    int Green;
    int Blue;
};

//image.cpp

int width,height;
RGB **data;
int bytesPerPixel = 8; //if RGB or 24 Bit image
int i,j;
int value=0;

Image::Image()
{
    //constuctor declaration
}
Image::~Image()
{
    // destructor declaration
} 
 char *ptr=(char*)(&data[0][0]);

 //function to capture image

int  Image::capture()
{
   int i,j;
  unsigned byte** array_2D=NULL;

      std::cin>>height;
      std::cin>>width;

    array_2D = new unsigned byte*[height];
     if(array_2D == NULL) 
        return 0; // return if memory not allocated


     for(int j=0; j<height; j++)
      {
            array_2D[j] = new unsigned byte*[width];
            if(array_2D[j] == NULL) 
                return 0;       // return if memory not allocated
      }

          for(j=0; j<height; j++) // traverse height (or rows)
           {
                for(int i=0; i<width; i++) // traverse width (or columns)
                   {
                       array_2D[j][i] = value++;// update value at current (i, j)
                   }
                     value = 0;
           }
}

here i want to read rgb values for the image in an array i am not getting that one. and u check the pointers in the program. thanq for replying.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.