Canon EOS SDK を使用しており、カメラ ストリームでライブ グリーンスクリーンを実現したいと考えています。
ピクセル操作を最適化した単純なグリーンスクリーン アルゴリズムがあります。
public Bitmap greenScreen(Bitmap input, int tolerance)
{
FastPixel fpinput = new FastPixel(input);
fpinput.Lock();
Bitmap output = new Bitmap(input.Width, input.Height);
FastPixel fpoutput = new FastPixel(output);
fpoutput.Lock();
for (int y = 0; y < output.Height; y++)
{
for (int x = 0; x < output.Width; x++)
{
Color camColor = fpinput.GetPixel(x, y);
// Every component (red, green, and blue) can have a value from 0 to 255, so determine the extremes
byte max = Math.Max(Math.Max(camColor.R, camColor.G), camColor.B);
byte min = Math.Min(Math.Min(camColor.R, camColor.G), camColor.B);
bool replace =
camColor.G != min // green is not the smallest value
&& (camColor.G == max // green is the bsiggest value
|| max - camColor.G < 8) // or at least almost the biggest value
&& (max - min) > tolerance; // minimum difference between smallest/biggest value (avoid grays)
if (!replace)
fpoutput.SetPixel(x, y, camColor);
}
}
fpinput.Unlock(true);
fpoutput.Unlock(true);
return fpoutput.Bitmap;
}
800x600 の写真の場合、私の i5 では約 300 ミリ秒かかります。もちろん、これはスムーズなライブストリームには十分な速度ではありません.
どのような最適化オプションがありますか? GPU関数を使用する機会はありますか? チャンスとは?Canon カメラで DirectShow を使用できません (ドライバーが存在しません)。