0

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.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by sravs25
0
//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.

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.