0

i have a bitmask in c++ with text on it. The bitmask gives me a value of 255 for pixels that have no text covering it. I would like to get coordinates (x,y) of any pixel or group of pixels with this value. What process should i follow? This could be done in java or native.

  • Could you please help me with a function for this in c++. In not good at c++ but need this part of code. – user3057156 Mar 25 '14 at 16:38
  • Do you know how to search an array for a value? – Thomas Matthews Mar 25 '14 at 16:40
  • Yes, using loops. But for the bitmask what function will i use to get the value at say x,y..is it similar to bitmaps? and can i pass this to java and do the manipulation there? – user3057156 Mar 25 '14 at 16:44
  • Given the starting location (address) of a bitmask, you could cheat and typecast it to a 2 dimensional array or use the formula: `index = row * bytes_in_column + column;`. – Thomas Matthews Mar 25 '14 at 16:48

1 Answers1

0

Here's a snippet that searches a bitmask (array of bytes) for the value 255 and pushes the <x,y> coordinate into a vector:

const unsigned bytes_per_row = 64U; // You need to change this according to the bitmask size.
const unsigned row_quantity = 32;   // Change per bitmask dimensions.
typedef std::pair<unsigned int, unsigned int> Location;
typedef std::vector<Location> Location_Container;
Location_Container text_locations;
uint8_t const * p_bitmask; // This needs to point to the first byte in the bitmask.
for (unsigned int row = 0; row < row_quantity; ++row)
{
    for (unsigned int column = 0; column < bytes_per_row; ++column)
    {
        uint8_t byte = *p_bitmask++; // Get byte from bitmask
        if (byte == 255)
        {
            Location l = Location(row, column);
            text_locations.push_back(location);
        }
    }
}
// At this point the vector text_locations contains the coordinates of
//    all the values of 255 in the bitmask.

Is this what you were referring to?
It finds a 255 and stores the location (row, column) into a vector.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154