• Sort Posts • 10 replies

I am using the wordreco sample android.

I need to get specific coordinates (x,y) of an area within a text's bounding box where there is no text.

which shows areas coverd by text but i cannot get the coordinates to use for further processing. Please help me on how to obtain them.

Thank you,

B.B

Hi,

could you explain this a bit better?

what do you mean with:

a text's bounding box where there is no text

?

Sory for not being so clear.

In the textreco sample, when text is detected a tectangular box is drawn around it. I need to select any area from within this box that is not coverd by text. i therefore need coordinates of any area that is not coverd by text but lies within this box.

Ok, I understand it now :-)

I think the getMask() method is the right one to use in this case; as the documention says, this function:

Returns an image representing the bit mask of the letters in the word.
Each pixel in the image is represented by a byte (8-bit value).
A value of 255 represents an empty area, i.e. a pixel not covered
by any letter of the word.
If a pixel is covered by a letter, then the pixel value represents
the position of that letter in the word, i.e. 0 for the first character,
1 for the second, 2 for the third, and so on.

So, you could iterate over the pixels of the image and based on the position (row and column) of the pixel in the image, you should be able to compute the coordinates that you are looking for...  it's just about maths :-)

Could i get  more help on the maths as stated? How do i get the coordinates of the area with pixel value 255 from the bitmask and convert the coordinates to match those of the original image? (im assuming the bitmask size is no the same as the original one).

I hope this is the right forum.

const unsigned bytes_per_row = 5U; // You need to change this according to the bitmask size.
const unsigned row_quantity = 10;   // Change per bitmask dimensions.
for (unsigned int row = 0; row < row_quantity; ++row)
{
for (unsigned int column = 0; column < bytes_per_row; ++column)
{
if (byte == 255)
{
xCoord = row;
yCoord = column;

break;
}
}
}

Currently i am trying this out in c++but i get an error could i get any further help?
Try adjusting the code as follows:
```const QCAR::Image *mask = word.getMask();

const unsigned char *pixels = mask->getPixels();

int xCoord = 0;
int yCoord = 0;

for (int row = 0; row < num_rows; ++row)
{
for (int column = 0; column < num_cols; ++column)
{
unsigned char byte = pixels[row*num_cols + column]; // Get byte from mask
if (byte == 255)
{
xCoord = row;
yCoord = column;

break;
}
}
}
```

I modified the code and i get an error at his assignment:

const unsigned char *pixels = mask->getPixels();

It says invalid conversion from 'void const*' to 'unsigned char const'

try this:
const unsigned char *pixels = (const unsigned char *)mask->getPixels();

That works okay :)

Great :-)