You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openCV/OpenCV/Form1.cs

75 lines
1.9 KiB

3 years ago
using System;
using System.Windows.Forms;
using OpenCvSharp;
namespace OpenCV
{
public partial class Form1 : Form
{
CvCapture capture;
IplImage src;
string filePath;
int frameCount = 0;
3 years ago
public Form1()
{
InitializeComponent();
}
private string FindFileName()
{
string path = "";
OpenFileDialog dialog = new OpenFileDialog();
DialogResult dialogResult = dialog.ShowDialog();
if (dialogResult == DialogResult.OK)
path = dialog.FileName;
return path;
}
3 years ago
private void Form1_Load(object sender, EventArgs e)
{
try
{
//capture = CvCapture.FromCamera(CaptureDevice.DShow, 0);
//capture.SetCaptureProperty(CaptureProperty.FrameWidth, 640);
//capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480);
filePath = FindFileName();
if (String.IsNullOrEmpty(filePath))
return;
3 years ago
capture = CvCapture.FromFile(filePath);
timer1.Enabled = true;
3 years ago
}
catch (Exception ex)
{
timer1.Enabled = false;
MessageBox.Show(ex.Message);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
frameCount++;
label1.Text = $"Frame: {frameCount} / {capture.FrameCount}";
3 years ago
src = capture.QueryFrame();
if (frameCount == capture.FrameCount)
{
frameCount = 0;
capture = CvCapture.FromFile(filePath);
}
3 years ago
pictureBoxIpl1.ImageIpl = src;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cv.ReleaseImage(src);
if (src != null)
src.Dispose();
}
}
}