Skip to content

Commit

Permalink
[1.1] Adapt components
Browse files Browse the repository at this point in the history
- Adapt components based on size of input device
- Moved camera device option
- Other misc. features
  • Loading branch information
Pheggas committed Feb 17, 2022
1 parent 4ed947c commit 5d1bbd5
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 54 deletions.
Binary file modified .vs/bakalarka_final/v16/.suo
Binary file not shown.
64 changes: 41 additions & 23 deletions bakalarka_final/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 45 additions & 31 deletions bakalarka_final/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -57,20 +49,18 @@ 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<Bgr, byte>().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)
{
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();
Expand All @@ -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;
Expand All @@ -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: ";
Expand All @@ -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: ";
Expand All @@ -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)
Expand All @@ -149,41 +151,53 @@ 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)
{
chooseCameraDeviceToolStripMenuItem.DropDownItems.Add(Data.Name);
}
}

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";
}

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);
}

Expand Down
Binary file modified bakalarka_final/bin/Debug/bakalarka_final.exe
Binary file not shown.
Binary file modified bakalarka_final/bin/Debug/bakalarka_final.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified bakalarka_final/obj/Debug/bakalarka_final.exe
Binary file not shown.
Binary file modified bakalarka_final/obj/Debug/bakalarka_final.pdb
Binary file not shown.

0 comments on commit 5d1bbd5

Please sign in to comment.