동영상 파일 출력

remotes/origin/master
syneffort 3 years ago
parent c0a3a6478b
commit 352e3c2235
  1. 15
      OpenCV/Form1.Designer.cs
  2. 34
      OpenCV/Form1.cs

@ -32,6 +32,7 @@ namespace OpenCV
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.pictureBoxIpl1 = new OpenCvSharp.UserInterface.PictureBoxIpl(); this.pictureBoxIpl1 = new OpenCvSharp.UserInterface.PictureBoxIpl();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxIpl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxIpl1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -40,20 +41,30 @@ namespace OpenCV
this.pictureBoxIpl1.Location = new System.Drawing.Point(12, 12); this.pictureBoxIpl1.Location = new System.Drawing.Point(12, 12);
this.pictureBoxIpl1.Name = "pictureBoxIpl1"; this.pictureBoxIpl1.Name = "pictureBoxIpl1";
this.pictureBoxIpl1.Size = new System.Drawing.Size(640, 480); this.pictureBoxIpl1.Size = new System.Drawing.Size(640, 480);
this.pictureBoxIpl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBoxIpl1.TabIndex = 0; this.pictureBoxIpl1.TabIndex = 0;
this.pictureBoxIpl1.TabStop = false; this.pictureBoxIpl1.TabStop = false;
// //
// timer1 // timer1
// //
this.timer1.Enabled = true;
this.timer1.Interval = 33; this.timer1.Interval = 33;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
// //
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(20, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 12);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(662, 503); this.ClientSize = new System.Drawing.Size(662, 503);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBoxIpl1); this.Controls.Add(this.pictureBoxIpl1);
this.Name = "Form1"; this.Name = "Form1";
this.Text = "Form1"; this.Text = "Form1";
@ -61,6 +72,7 @@ namespace OpenCV
this.Load += new System.EventHandler(this.Form1_Load); this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxIpl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxIpl1)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@ -68,6 +80,7 @@ namespace OpenCV
private OpenCvSharp.UserInterface.PictureBoxIpl pictureBoxIpl1; private OpenCvSharp.UserInterface.PictureBoxIpl pictureBoxIpl1;
private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
} }
} }

@ -9,19 +9,39 @@ namespace OpenCV
CvCapture capture; CvCapture capture;
IplImage src; IplImage src;
string filePath;
int frameCount = 0;
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
} }
private string FindFileName()
{
string path = "";
OpenFileDialog dialog = new OpenFileDialog();
DialogResult dialogResult = dialog.ShowDialog();
if (dialogResult == DialogResult.OK)
path = dialog.FileName;
return path;
}
private void Form1_Load(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e)
{ {
try try
{ {
capture = CvCapture.FromCamera(CaptureDevice.DShow, 0); //capture = CvCapture.FromCamera(CaptureDevice.DShow, 0);
capture.SetCaptureProperty(CaptureProperty.FrameWidth, 640); //capture.SetCaptureProperty(CaptureProperty.FrameWidth, 640);
capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480); //capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480);
filePath = FindFileName();
if (String.IsNullOrEmpty(filePath))
return;
capture = CvCapture.FromFile(filePath);
timer1.Enabled = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -32,7 +52,15 @@ namespace OpenCV
private void timer1_Tick(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e)
{ {
frameCount++;
label1.Text = $"Frame: {frameCount} / {capture.FrameCount}";
src = capture.QueryFrame(); src = capture.QueryFrame();
if (frameCount == capture.FrameCount)
{
frameCount = 0;
capture = CvCapture.FromFile(filePath);
}
pictureBoxIpl1.ImageIpl = src; pictureBoxIpl1.ImageIpl = src;
} }

Loading…
Cancel
Save