我在c ++中有一个带有文本的位掩码。对于没有文本覆盖它的像素,位掩码给出了值255。我想获得具有此值的任何像素或像素组的坐标(x,y)。我应该遵循什么过程?这可以用java或native来完成。
答案 0 :(得分:0)
这是一个搜索位掩码(字节数组)的值为255的片段,并将<x,y>
坐标推送到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.
这是你指的是什么? 它找到255并将位置(行,列)存储到向量中。