diff --git a/.vs/bakalarka_final/v16/.suo b/.vs/bakalarka_final/v16/.suo index 4a73577..c0c6548 100644 Binary files a/.vs/bakalarka_final/v16/.suo and b/.vs/bakalarka_final/v16/.suo differ diff --git a/bakalarka_final/Form1.Designer.cs b/bakalarka_final/Form1.Designer.cs index 4b70a63..7ae968d 100644 --- a/bakalarka_final/Form1.Designer.cs +++ b/bakalarka_final/Form1.Designer.cs @@ -39,12 +39,14 @@ private void InitializeComponent() this.minFaceSize_L = new System.Windows.Forms.Label(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.chooseCameraDeviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.languageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.englishToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.slovakToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.label1 = new System.Windows.Forms.Label(); this.timer1 = new System.Windows.Forms.Timer(this.components); + this.deviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.chooseCameraDeviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.aspectRatioToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.minFaceSize)).BeginInit(); this.menuStrip1.SuspendLayout(); @@ -52,7 +54,7 @@ private void InitializeComponent() // // pictureBox1 // - this.pictureBox1.Location = new System.Drawing.Point(12, 65); + this.pictureBox1.Location = new System.Drawing.Point(12, 27); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(615, 404); this.pictureBox1.TabIndex = 0; @@ -60,7 +62,7 @@ private void InitializeComponent() // // button1 // - this.button1.Location = new System.Drawing.Point(633, 65); + this.button1.Location = new System.Drawing.Point(633, 27); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; @@ -71,7 +73,7 @@ private void InitializeComponent() // count_L // this.count_L.AutoSize = true; - this.count_L.Location = new System.Drawing.Point(633, 91); + this.count_L.Location = new System.Drawing.Point(633, 53); this.count_L.Name = "count_L"; this.count_L.Size = new System.Drawing.Size(35, 13); this.count_L.TabIndex = 2; @@ -80,7 +82,7 @@ private void InitializeComponent() // side_L // this.side_L.AutoSize = true; - this.side_L.Location = new System.Drawing.Point(633, 104); + this.side_L.Location = new System.Drawing.Point(633, 66); this.side_L.Name = "side_L"; this.side_L.Size = new System.Drawing.Size(35, 13); this.side_L.TabIndex = 3; @@ -89,7 +91,7 @@ private void InitializeComponent() // rectEmpty_L // this.rectEmpty_L.AutoSize = true; - this.rectEmpty_L.Location = new System.Drawing.Point(633, 117); + this.rectEmpty_L.Location = new System.Drawing.Point(633, 79); this.rectEmpty_L.Name = "rectEmpty_L"; this.rectEmpty_L.Size = new System.Drawing.Size(35, 13); this.rectEmpty_L.TabIndex = 4; @@ -98,7 +100,7 @@ private void InitializeComponent() // faceCount_L // this.faceCount_L.AutoSize = true; - this.faceCount_L.Location = new System.Drawing.Point(674, 413); + this.faceCount_L.Location = new System.Drawing.Point(674, 375); this.faceCount_L.Name = "faceCount_L"; this.faceCount_L.Size = new System.Drawing.Size(35, 13); this.faceCount_L.TabIndex = 5; @@ -106,7 +108,7 @@ private void InitializeComponent() // // minFaceSize // - this.minFaceSize.Location = new System.Drawing.Point(645, 237); + this.minFaceSize.Location = new System.Drawing.Point(645, 199); this.minFaceSize.Maximum = 1000; this.minFaceSize.Minimum = 1; this.minFaceSize.Name = "minFaceSize"; @@ -118,7 +120,7 @@ private void InitializeComponent() // minFaceSize_L // this.minFaceSize_L.AutoSize = true; - this.minFaceSize_L.Location = new System.Drawing.Point(655, 221); + this.minFaceSize_L.Location = new System.Drawing.Point(655, 183); this.minFaceSize_L.Name = "minFaceSize_L"; this.minFaceSize_L.Size = new System.Drawing.Size(13, 13); this.minFaceSize_L.TabIndex = 7; @@ -127,7 +129,8 @@ private void InitializeComponent() // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.optionsToolStripMenuItem}); + this.optionsToolStripMenuItem, + this.deviceToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(843, 24); @@ -137,46 +140,38 @@ private void InitializeComponent() // optionsToolStripMenuItem // this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.chooseCameraDeviceToolStripMenuItem, this.languageToolStripMenuItem}); this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.optionsToolStripMenuItem.Text = "Options"; // - // chooseCameraDeviceToolStripMenuItem - // - this.chooseCameraDeviceToolStripMenuItem.Name = "chooseCameraDeviceToolStripMenuItem"; - this.chooseCameraDeviceToolStripMenuItem.Size = new System.Drawing.Size(193, 22); - this.chooseCameraDeviceToolStripMenuItem.Text = "Choose camera device"; - this.chooseCameraDeviceToolStripMenuItem.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.chooseCameraDeviceToolStripMenuItem_DropDownItemClicked); - // // languageToolStripMenuItem // this.languageToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.englishToolStripMenuItem, this.slovakToolStripMenuItem}); this.languageToolStripMenuItem.Name = "languageToolStripMenuItem"; - this.languageToolStripMenuItem.Size = new System.Drawing.Size(193, 22); + this.languageToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.languageToolStripMenuItem.Text = "Language"; // // englishToolStripMenuItem // this.englishToolStripMenuItem.Name = "englishToolStripMenuItem"; - this.englishToolStripMenuItem.Size = new System.Drawing.Size(131, 22); + this.englishToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.englishToolStripMenuItem.Text = "English"; this.englishToolStripMenuItem.Click += new System.EventHandler(this.englishToolStripMenuItem_Click); // // slovakToolStripMenuItem // this.slovakToolStripMenuItem.Name = "slovakToolStripMenuItem"; - this.slovakToolStripMenuItem.Size = new System.Drawing.Size(131, 22); + this.slovakToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.slovakToolStripMenuItem.Text = "Slovenčina"; this.slovakToolStripMenuItem.Click += new System.EventHandler(this.slovakToolStripMenuItem_Click); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(727, 342); + this.label1.Location = new System.Drawing.Point(727, 304); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(35, 13); this.label1.TabIndex = 9; @@ -186,6 +181,27 @@ private void InitializeComponent() // this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // + // deviceToolStripMenuItem + // + this.deviceToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.chooseCameraDeviceToolStripMenuItem, + this.aspectRatioToolStripMenuItem}); + this.deviceToolStripMenuItem.Name = "deviceToolStripMenuItem"; + this.deviceToolStripMenuItem.Size = new System.Drawing.Size(54, 20); + this.deviceToolStripMenuItem.Text = "Device"; + // + // chooseCameraDeviceToolStripMenuItem + // + this.chooseCameraDeviceToolStripMenuItem.Name = "chooseCameraDeviceToolStripMenuItem"; + this.chooseCameraDeviceToolStripMenuItem.Size = new System.Drawing.Size(193, 22); + this.chooseCameraDeviceToolStripMenuItem.Text = "Choose camera device"; + // + // aspectRatioToolStripMenuItem + // + this.aspectRatioToolStripMenuItem.Name = "aspectRatioToolStripMenuItem"; + this.aspectRatioToolStripMenuItem.Size = new System.Drawing.Size(193, 22); + this.aspectRatioToolStripMenuItem.Text = "Aspect ratio"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -226,11 +242,13 @@ private void InitializeComponent() private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem chooseCameraDeviceToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem languageToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem englishToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem slovakToolStripMenuItem; private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.ToolStripMenuItem deviceToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem chooseCameraDeviceToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem aspectRatioToolStripMenuItem; } } diff --git a/bakalarka_final/Form1.cs b/bakalarka_final/Form1.cs index f3d59de..6bcce76 100644 --- a/bakalarka_final/Form1.cs +++ b/bakalarka_final/Form1.cs @@ -39,14 +39,6 @@ public Form1() { InitializeComponent(); haar = new CascadeClassifier(cfgFile.haarFile); //initialize haar cascade - if (currentLanguage.ToString() == "sk-SK") // and app preferences with this variable is empty - { - SK(); - } - else // and app preferences with this variable is empty - { - EN(); - } } private void ProcessFrame(object sender, EventArgs e) @@ -57,12 +49,10 @@ private void ProcessFrame(object sender, EventArgs e) if (camera != null) //comes from button1.click { camera.Retrieve(frame, 0); - //pictureBox1.Image = Image.FromHbitmap(cFrame cFrame = frame.ToImage().Resize(pictureBox1.Width, pictureBox1.Height, Inter.Cubic); //edit image to fit the pictureBox; convert it to System class image Mat grayFrame = new Mat(); CvInvoke.CvtColor(cFrame, grayFrame, ColorConversion.Bgr2Gray); //convert image to grayscale Rectangle[] faces = haar.DetectMultiScale(grayFrame, 1.1, 3, minSize, Size.Empty); //detect - //CvInvoke.Line(cFrame, px, py, new MCvScalar(0, 0, 255), 2); // draw red if (faces.Length > 0) { foreach (var face in faces) @@ -70,7 +60,7 @@ private void ProcessFrame(object sender, EventArgs e) if (face.Width >= minFaceSize.Value) { faceCount_L.Text = faces.Length.ToString(); - CvInvoke.Rectangle(cFrame, face, new Bgr(Color.Green).MCvScalar, 2); //draw + CvInvoke.Rectangle(cFrame, face, new Bgr(Color.Green).MCvScalar, 2); count_L.Text = count.ToString() + count_LT; side_L.Text = side_LT + faceSide.ToString(); rectEmpty_L.Text = rectEmpty_LT + rectEmpty.ToString(); @@ -85,7 +75,6 @@ private void ProcessFrame(object sender, EventArgs e) if (faceSide == false && face.Location.X < 200) { timer1.Start(); - //CvInvoke.Line(cFrame, px, py, new MCvScalar(0, 255, 0), 4); //draw green line if people passed faceSide = true; count += 1; rectEmpty = 0; @@ -101,17 +90,13 @@ private void ProcessFrame(object sender, EventArgs e) GC.Collect(); //execute pressure releasing } - - private void button1_Click(object sender, EventArgs e) - { - Webcam(); - } - void EN() { optionsToolStripMenuItem.Text = "Options"; - chooseCameraDeviceToolStripMenuItem.Text = "Choose camera device"; languageToolStripMenuItem.Text = "Language"; + deviceToolStripMenuItem.Text = "Device"; + chooseCameraDeviceToolStripMenuItem.Text = "Choose camera device"; + aspectRatioToolStripMenuItem.Text = "Aspect ratio"; count_LT = " people counted"; side_LT = "Face in ROI: "; rectEmpty_LT = "Frames without face in ROI: "; @@ -122,8 +107,10 @@ void EN() void SK() { optionsToolStripMenuItem.Text = "Možnosti"; - chooseCameraDeviceToolStripMenuItem.Text = "Zvoliť zaznamenávacie zariadenie"; languageToolStripMenuItem.Text = "Jazyk"; + deviceToolStripMenuItem.Text = "Zariadenie"; + chooseCameraDeviceToolStripMenuItem.Text = "Zvoliť zaznamenávacie zariadenie"; + aspectRatioToolStripMenuItem.Text = "Pomer strán"; count_LT = " započítaných ľudí"; side_LT = "Tvár v ROI: "; rectEmpty_LT = "Počet snímkov bez tváre v ROI: "; @@ -135,11 +122,26 @@ void Webcam() { if (camera != null) camera.Dispose(); camera = new VideoCapture(cameraIndex); + adaptPictureBox(); camera.QueryFrame(); //necessarry camera.Start(); //necessarry Application.Idle += ProcessFrame; //pass it to ProcessFrame void } + void adaptPictureBox() + { + pictureBox1.Height = camera.Height; + pictureBox1.Width = camera.Width; + button1.Location = new Point(pictureBox1.Location.X + pictureBox1.Width + 6, pictureBox1.Location.Y); + count_L.Location = new Point(button1.Location.X, button1.Location.Y + button1.Size.Height + 3); + side_L.Location = new Point(count_L.Location.X, count_L.Location.Y + count_L.Height + 3); + rectEmpty_L.Location = new Point(side_L.Location.X, side_L.Location.Y + side_L.Height + 3); + minFaceSize_L.Location = new Point(rectEmpty_L.Location.X, rectEmpty_L.Location.Y + rectEmpty_L.Height + 60); + minFaceSize.Location = new Point(minFaceSize_L.Location.X, minFaceSize_L.Location.Y + minFaceSize_L.Height + 3); + minFaceSize.Maximum = pictureBox1.Height; + this.Size = new Size(button1.Location.X + button1.Width + 120, pictureBox1.Location.Y + pictureBox1.Height + 50); + } + void drawLine() { if (timer1.Enabled == false) @@ -149,20 +151,22 @@ void drawLine() else CvInvoke.Line(cFrame, px, py, new MCvScalar(0, 255, 0), 2); } - private void timer1_Tick(object sender, EventArgs e) - { - timer1.Stop(); - } - private void Form1_Load(object sender, EventArgs e) { - p1x = 200 ; - p1y = 0 ; - p2x = 200 ; + p1x = 200; + p1y = 0; + p2x = 200; p2y = pictureBox1.Height; timer1.Interval = 100; // 0,1 second timer1.Enabled = true; - minFaceSize.Maximum = pictureBox1.Height; + if (currentLanguage.ToString() == "sk-SK") + { + SK(); + } + else + { + EN(); + } DataCollector = new FilterInfoCollection(FilterCategory.VideoInputDevice); foreach (FilterInfo Data in DataCollector) { @@ -170,6 +174,16 @@ private void Form1_Load(object sender, EventArgs e) } } + private void button1_Click(object sender, EventArgs e) + { + Webcam(); + } + + private void timer1_Tick(object sender, EventArgs e) + { + timer1.Stop(); + } + private void trackBar1_Scroll(object sender, EventArgs e) { minFaceSize_L.Text = minFaceSize_LT + minFaceSize.Value.ToString() + " px"; @@ -177,13 +191,13 @@ private void trackBar1_Scroll(object sender, EventArgs e) private void englishToolStripMenuItem_Click(object sender, EventArgs e) { - EN(); // write this selection down to app preferences to keep it saved even after app closes + EN(); trackBar1_Scroll(sender, e); } private void slovakToolStripMenuItem_Click(object sender, EventArgs e) { - SK(); // write this selection down to app preferences to keep it saved even after app closes + SK(); trackBar1_Scroll(sender, e); } diff --git a/bakalarka_final/bin/Debug/bakalarka_final.exe b/bakalarka_final/bin/Debug/bakalarka_final.exe index b844fc8..c6742a6 100644 Binary files a/bakalarka_final/bin/Debug/bakalarka_final.exe and b/bakalarka_final/bin/Debug/bakalarka_final.exe differ diff --git a/bakalarka_final/bin/Debug/bakalarka_final.pdb b/bakalarka_final/bin/Debug/bakalarka_final.pdb index c8a40d1..5cd6330 100644 Binary files a/bakalarka_final/bin/Debug/bakalarka_final.pdb and b/bakalarka_final/bin/Debug/bakalarka_final.pdb differ diff --git a/bakalarka_final/obj/Debug/bakalarka_final.csproj.GenerateResource.cache b/bakalarka_final/obj/Debug/bakalarka_final.csproj.GenerateResource.cache index 254040e..92dc16d 100644 Binary files a/bakalarka_final/obj/Debug/bakalarka_final.csproj.GenerateResource.cache and b/bakalarka_final/obj/Debug/bakalarka_final.csproj.GenerateResource.cache differ diff --git a/bakalarka_final/obj/Debug/bakalarka_final.csprojAssemblyReference.cache b/bakalarka_final/obj/Debug/bakalarka_final.csprojAssemblyReference.cache index 49b547e..e6f8590 100644 Binary files a/bakalarka_final/obj/Debug/bakalarka_final.csprojAssemblyReference.cache and b/bakalarka_final/obj/Debug/bakalarka_final.csprojAssemblyReference.cache differ diff --git a/bakalarka_final/obj/Debug/bakalarka_final.exe b/bakalarka_final/obj/Debug/bakalarka_final.exe index b844fc8..c6742a6 100644 Binary files a/bakalarka_final/obj/Debug/bakalarka_final.exe and b/bakalarka_final/obj/Debug/bakalarka_final.exe differ diff --git a/bakalarka_final/obj/Debug/bakalarka_final.pdb b/bakalarka_final/obj/Debug/bakalarka_final.pdb index c8a40d1..5cd6330 100644 Binary files a/bakalarka_final/obj/Debug/bakalarka_final.pdb and b/bakalarka_final/obj/Debug/bakalarka_final.pdb differ