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)