関連するコードは次のとおりです。
フォームの load メソッドで:
Application.Idle += new EventHandler(delegate(object s, EventArgs ea)
{
if (!recording)
{
currentFrame = getFrame();
ib.Image = currentFrame;
}
else
{
ib.Image = recFrame;
}
});
ボタンを押すと (ib はフォーム上の ImageBox です):
Measurements measurements = new Measurements();
String name = txtSampleName.Text;
ib.Image = recFrame;
stopwatch.Start();
recording = true;
while ((count = (int)Math.Floor(stopwatch.ElapsedMilliseconds/(double)1000)) < finalTime)
{
currentFrame = getFrame();
Measurement currentMeasurement = new Measurement(name, currentFrame);
measurements.add(currentMeasurement);
}
recording = false;
stopwatch.Stop();
measurements.write(txtDirectory.Text);
問題は、フレームが実際に更新されていないことです。currentFrame は、ループが開始する前のフレームの値を取ります。recFrame は ib.Image に表示されません - ib はループ中にハングするだけです - そして本来あるべき recFrame で満たされません)。currentMeasurement は測定値リストに追加されますが、その中のフレームはカメラからの現在のフレームではありません。getFrame() からのコードの概要を以下に示します。これは、現時点で Web カメラからのものを返さないか、現在のフレームが古い値を取得していることに関係なく、次のいずれかです。
private Image<Bgr, Byte> getFrame()
{
// get the frame
Image<Bgr, Byte> frame = capture.QueryFrame();
// draw some stuff on top of the frame
// ...
// return
return frame;
}
何かが完了するのを待つために、ある種の遅延を追加する必要がありますか? Thread.Sleep を入れてみましたが、何の役にも立ちません。問題が何であるかわからないので、賢明な解決策を探すことができませんでした。後で測定のフレームを AVI ファイルにエクスポートすると、すべてのフレームがループ開始前の currentFrame の値を持ち、変更されません。
何か案は?
多くの感謝とともに、
フロスコイ。
編集: 行 currentMeasurement = new Measurement(name,currentFrame) で currentFrame.Copy() を使用すると、現在のキャプチャされたフレームが実際にリストに入れられ、後で AVI ファイルに書き込まれます。よくわかりませんが、なぜですか?また、recFrame は ib にまだ表示されていないので、ここでも何が起こっているのかわかりませんか?