From 352e3c223595d1c8131404a866d1766a8779eb33 Mon Sep 17 00:00:00 2001 From: syneffort Date: Sat, 11 Jun 2022 08:16:19 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8F=99=EC=98=81=EC=83=81=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenCV/Form1.Designer.cs | 15 ++++++++++++++- OpenCV/Form1.cs | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/OpenCV/Form1.Designer.cs b/OpenCV/Form1.Designer.cs index b2bc072..ec25b03 100644 --- a/OpenCV/Form1.Designer.cs +++ b/OpenCV/Form1.Designer.cs @@ -32,6 +32,7 @@ namespace OpenCV this.components = new System.ComponentModel.Container(); this.pictureBoxIpl1 = new OpenCvSharp.UserInterface.PictureBoxIpl(); this.timer1 = new System.Windows.Forms.Timer(this.components); + this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxIpl1)).BeginInit(); this.SuspendLayout(); // @@ -40,20 +41,30 @@ namespace OpenCV this.pictureBoxIpl1.Location = new System.Drawing.Point(12, 12); this.pictureBoxIpl1.Name = "pictureBoxIpl1"; this.pictureBoxIpl1.Size = new System.Drawing.Size(640, 480); + this.pictureBoxIpl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBoxIpl1.TabIndex = 0; this.pictureBoxIpl1.TabStop = false; // // timer1 // - this.timer1.Enabled = true; this.timer1.Interval = 33; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(662, 503); + this.Controls.Add(this.label1); this.Controls.Add(this.pictureBoxIpl1); this.Name = "Form1"; this.Text = "Form1"; @@ -61,6 +72,7 @@ namespace OpenCV this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxIpl1)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -68,6 +80,7 @@ namespace OpenCV private OpenCvSharp.UserInterface.PictureBoxIpl pictureBoxIpl1; private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Label label1; } } diff --git a/OpenCV/Form1.cs b/OpenCV/Form1.cs index a824d54..a5808cd 100644 --- a/OpenCV/Form1.cs +++ b/OpenCV/Form1.cs @@ -9,19 +9,39 @@ namespace OpenCV CvCapture capture; IplImage src; + string filePath; + int frameCount = 0; + 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; + } + 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); + //capture = CvCapture.FromCamera(CaptureDevice.DShow, 0); + //capture.SetCaptureProperty(CaptureProperty.FrameWidth, 640); + //capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480); + filePath = FindFileName(); + if (String.IsNullOrEmpty(filePath)) + return; + capture = CvCapture.FromFile(filePath); + timer1.Enabled = true; } catch (Exception ex) { @@ -32,7 +52,15 @@ namespace OpenCV private void timer1_Tick(object sender, EventArgs e) { + frameCount++; + label1.Text = $"Frame: {frameCount} / {capture.FrameCount}"; src = capture.QueryFrame(); + if (frameCount == capture.FrameCount) + { + frameCount = 0; + capture = CvCapture.FromFile(filePath); + } + pictureBoxIpl1.ImageIpl = src; }