public partial class MainForm : Form
{
private IplImage frame;
private IplImage imgMain;
private CvCapture VideoCapture;
private IplImage frames;
public MainForm()
{
InitializeComponent();
}
private void btnVideo_Click(object sender, EventArgs e)
{
double vidWidth, vidHeight;
if (btnVideo.Text.CompareTo("Start Video") == 0)
{
try
{
VideoCapture = cvlib.cvCreateCameraCapture(0);
if (VideoCapture == null)
{
MessageBox.Show("Failed");
return;
}
btnVideo.Text = "Stop Video";
cvlib.cvSetCaptureProperty(VideoCapture, cvlib.CV_CAP_PROP_FRAME_WIDTH, 640);
cvlib.cvSetCaptureProperty(VideoCapture, cvlib.CV_CAP_PROP_FRAME_HEIGHT, 320);
frames = cvlib.cvQueryFrame(VideoCapture);
vidWidth = cvlib.cvGetCaptureProperty(VideoCapture, cvlib.CV_CAP_PROP_FRAME_WIDTH);
vidHeight = cvlib.cvGetCaptureProperty(VideoCapture, cvlib.CV_CAP_PROP_FRAME_HEIGHT);
CamImageBox.Width = (int)vidWidth;
CamImageBox.Height = (int)vidHeight;
timerGrab.Interval = 1000;
timerGrab.Enabled = true;
}
catch (Exception excpt)
{
MessageBox.Show(excpt.Message);
}
}
else
{
btnVideo.Text = "Start Video";
timerGrab.Enabled = false;
if (VideoCapture == null)
{
cvlib.cvReleaseImage(frames);
VideoCapture = null;
}
}
}
private void timerGrab_Tick(object sender, EventArgs e)
{
frame = cvlib.cvQueryFrame(VideoCapture);
if (frame == null)
{
timerGrab.Stop();
MessageBox.Show("failed");
return;
}
imgMain = cvlib.cvCreateImage(cvlib.cvSize(640, 480), 8, 3);
CamImageBox.Image = cvlib.ToBitmap(imgMain, false);
cvlib.cvReleaseImage(imgMain);
}
}
我更改了我使用的库。
它现在是 cvwrappercs230 它是 c# 中 opencv 的包装器。
它还说 cvwrappercpp230 无法加载它的 dll。System.DLLNotfoundexception 即使 dll 在文件夹中。
现在的问题是它没有给我一个黑屏,而不是现在给我一个灰屏..
当我打破它时的问题在于Application.Run(new MainForm());
我也将间隔更改为 1000,因为有人说 42 太低但我仍然不知道问题出在哪里..
但是当我再次将间隔更改为 42 时。
断点的问题又回到了frame = cvlib.cvQueryFrame(videocapture)