public GetBackprojection ( |
||
image | ||
rectangle | ||
return | void |
public void GetBackprojection(UnmanagedImage image, Rectangle rectangle)
{
lock (sync)
{
int height = rectangle.Height;
int width = rectangle.Width;
int startx = rectangle.Left;
int starty = rectangle.Top;
int srcOffset = map.GetLength(1) - rectangle.Width;
PixelFormat format = image.PixelFormat;
int pixelSize = Bitmap.GetPixelFormatSize(format) / 8;
int stride = image.Stride;
int offset = stride - width * pixelSize;
unsafe
{
// Do work
fixed (float* map_ptr = &map[starty, startx])
{
byte* dst = (byte*)image.ImageData.ToPointer();
float* src = map_ptr;
// Check if image is grayscale (8bpp)
if (format == PixelFormat.Format8bppIndexed)
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, dst++, src++)
{
// probability map contains values between 0 and 1
*dst = (byte)Math.Floor(255f * (*src));
}
dst += offset;
src += srcOffset;
}
}
else // Image is 24bpp
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, dst += pixelSize, src++)
{
// probability map contains values between 0 and 1
byte value = (byte)Math.Floor(255f * (*src));
*(dst + 0) = value;
*(dst + 1) = value;
*(dst + 2) = value;
}
dst += offset;
src += srcOffset;
}
}
}
}
}
}
#endregion
Camshift::GetBackprojection ( ) : |
|
Camshift::GetBackprojection ( PixelFormat format ) : |
|
Camshift::GetBackprojection ( PixelFormat format, |