【发布时间】:2017-03-17 19:21:38
【问题描述】:
我想用一种特定颜色裁剪图像,就像透明蒙版一样,我想创建一个最小的框来包围图像。
我的意思的图片肯定会更好地解释它:
RGB(255,0,255) 是透明蒙版,绿色框代表所需的边界框。
我已经算出了边界框的顶线:
int nAlloc = (128 * 128) * 4;
unsigned char* buf = new unsigned char[nAlloc];
GetBitmapBits(hBMP, nAlloc, buf);
for(int i = 0; i < nAlloc; i += 4)
{
if(buf[i] == 255 && buf[i + 1] == 0 && buf[i + 2] == 255)
{
continue;
}
// If I hit a first non-transparent pixel,
// I can then calculate the row where is that pixel located.
else if(set_pixel == false)
{
set_pixel = true;
index = ceil((float)(i / 4.0 / 128.0));
}
... // Converting non-transparent pixels to Black&White
}
//I'm then drawing the bitmap to window like so:
TransparentBlt(hdc, 5, 305 - index, 128, 128, hDC, 0, 0, 128, 128, RGB(255, 0, 255));
我想,我也知道如何确定最后一行,但我不确定,也不知道如何找出边界框的边。
【问题讨论】:
-
您可能会使用flood fill 算法(这个问题有点像逆洪水填充)。
-
@JonathanPotter 那没有给我边界线,对吧?我不想影响任何像素,我只想得到弹跳框。我认为这对于这个问题来说太复杂了。
-
你实际上不会做任何填充,但递归算法会让你找到对象的边缘。
标签: c++ winapi image-processing