【发布时间】:2014-02-04 11:17:19
【问题描述】:
我正在开发一个程序,它将捕获四次图像 并将其保存到文件夹中
我所做的是将代码放入 for 循环中
但我的问题是它只保存第一个捕获的图像四次而不是捕获四次
private void Form1_Load(object sender, EventArgs e)
{
string path = @"C:\Users\\Jake_PC\\Desktop\\fitting\\";
System.IO.Directory.CreateDirectory(path);
bool useCam = true;
if (!useCam)
measureImage(null);
else
{
try
{
camera = new Capture();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
return;
}
Application.Idle += viewImage;
captureProcess = true;
}
}
private void btnCapture_Click(object sender, EventArgs e)
{
if (btnCapture.Text == "Back")
{
Application.Restart();
}
else
{
if (captureProcess == true)
{
for (int cap = 0; cap < 4; cap++)
{
string path = @"C:\\Users\\Jake_PC\\Desktop\\fitting\\";
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
ctr = dir.GetFiles().Length;
camera = new Capture();
System.Threading.Thread.Sleep(500);
Application.Idle -= viewImage;
SaveFileDialog dlg = new SaveFileDialog();
img.ToBitmap().Save(@"C:\\Users\\Jake_PC\\Desktop\\fitting\\" + ctr + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
camera.Dispose();
Form1_Load(sender, e);
}
}
}
}
【问题讨论】:
-
那段代码是一团乱七八糟的来回调用函数,没有明确定义的关注点和边界。你为什么不做一个功能来捕捉和保存图像而不是别的。完全独立于任何用户界面。在定义明确的环境中发现错误要容易得多。
-
你相机的 fps 是多少?如果是 30fps 左右,那么连续图像的差异几乎不会被注意到。
-
@Naren 我已经编辑了代码并尝试使用线程来延迟捕获但仍然是相同的结果
-
@newbie07 什么是“img”?是全局变量吗?请贴出整个程序找出错误。
标签: c# emgucv image-capture