AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

issues in theory

The forum is to discuss topics related to different areas of image processing and computer vision.

issues in theory

Postby Sam I. Ibraheem » Thu Feb 06, 2014 12:03 am

hey guys, and greetings from Syria. I'm new here and I loves the whole thing that's going on in the forum. I have some question and I was wondering if you could help me. So I've found this code and adjusted some things in it. It's for adjusting a cart's direction by detecting a black sector in an image acquired from a regular webcam, it's working just fine but I have some questions at the theoretical level:
1- is there any specific difference between the term "video frame" and "image"?? I mean a regular image and a frame captured from a webcam stream?
2- in the code there is this line:
Code: Select all
showframe1 = (Bitmap)eventArgs.Frame.Clone();

why casting is used??? I mean what's the data type that's the function Clone() is returning??
3- Also there is this portion:
Code: Select all
Grayscale gryfilt = new Grayscale(0.2125, 0.7154, 0.0721);
            gray = gryfilt.Apply(showframe1);
            Crop filter = new Crop(new Rectangle(1, 300, 600, 50));
            xxx = filter.Apply(gray);
            pictureBox2.Image = xxx;
            for ( Int32 b = 0; b < xxx.Width; b++)
            {
                if ((xxx.GetPixel(b, 1).R) < 60)

Now I know that's the BT709 Grayscaling is used to convert the RGB image to a gray-level one, but then this xxx.GetPixel(b,1).R is employed, I mean the R is indicating the red component of the image. That doesn't make any sense for the image is converted to gray??
4- does this code is considered "Computer vision" or "Image processing"?? is there any difference between the two????
5- Do you guys have books or references relating to this issue I can go to??
Thanks you guys, and here is the whole code:
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Imaging.ComplexFilters;
using AForge.Video;
using AForge.Video.DirectShow;
using AforgeWebcamVid.Properties;
using AForge.Math.Random;
using AForge.Imaging.Textures;
using AForge.Vision.Motion;
using System.IO.Ports;
namespace AforgeWebcamVid
{
    public partial class Form1 : Form
    {
        private FilterInfoCollection videocapturedevice;
        private VideoCaptureDevice finalvideosurce;
        Boolean isplaying = false;
        Boolean can = false;
        Boolean edg = false;
        Boolean col = false;

        Bitmap showframe;
        Bitmap showframe1;
        Mirror mirvid = new Mirror(false, true);
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            videocapturedevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            foreach (FilterInfo vc in videocapturedevice)
            {
                comboBox1.Items.Add(vc.Name);
                foreach (string s in SerialPort.GetPortNames())
                {
                    comboBox2.Items.Add(s);
                }
            }
            comboBox1.SelectedIndex = 1;
            Control.CheckForIllegalCrossThreadCalls = false;
        }
        private void button4_Click_1(object sender, EventArgs e)
        {
            button4.BackColor = Color.Red;
            if (can == false && edg == false || col == false) {
            }

            if (!isplaying)
            {
                finalvideosurce = new VideoCaptureDevice(videocapturedevice[comboBox1.SelectedIndex].MonikerString);
                finalvideosurce.NewFrame += new NewFrameEventHandler(finalvideosurce_NewFrame);
                finalvideosurce.Start();
                isplaying = true;
                button4.BackColor = Color.Red;
            }
            else
            {
                finalvideosurce.Stop();
                isplaying = false;
                button4.BackColor = Color.LimeGreen;
                pictureBox1.Image = null;
                pictureBox2.Image = null;
            }
        }
        void finalvideosurce_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap gray;
            Bitmap xxx;
            showframe = (Bitmap)eventArgs.Frame.Clone();
            mirvid.ApplyInPlace(showframe);
            ////////////////////////////////////////////////////////////////////////
            showframe.SetPixel(1, 55, Color.FromArgb(255, 255, 0));
            showframe.SetPixel(2, 55, Color.FromArgb(255, 255, 0));
            showframe.SetPixel(3, 55, Color.FromArgb(255, 255, 0));
            showframe.SetPixel(4, 55, Color.FromArgb(255, 255, 0));
            showframe.SetPixel(5, 55, Color.FromArgb(255, 255, 0));
            showframe.SetPixel(6, 55, Color.FromArgb(255, 255, 0));
            ////////////////////////////////////////////////////////////////////////
            pictureBox1.Image = showframe;
            showframe1 = (Bitmap)eventArgs.Frame.Clone();
            Crop colorcrop = new Crop(new Rectangle(1, 300, 600, 50));
            Bitmap clcrp = colorcrop.Apply(showframe1);
            Grayscale gryfilt = new Grayscale(0.2125, 0.7154, 0.0721);
            gray = gryfilt.Apply(showframe1);
            Crop filter = new Crop(new Rectangle(1, 300, 600, 50));
            xxx = filter.Apply(gray);
            pictureBox2.Image = xxx;
            for ( Int32 b = 0; b < xxx.Width; b++)
            {
                if ((xxx.GetPixel(b, 1).R) < 60)
                {
                    label16.Text = "black" + b.ToString();
                    if (b > 1 && b < 55)    serialPort1.Write("b");
                    if (b > 55 && b < 110)  serialPort1.Write("a");
                    if (b > 110 && b < 165) serialPort1.Write("9");
                    if (b > 165 && b < 220) serialPort1.Write("8");
                    if (b > 220 && b < 275) serialPort1.Write("7");
                    if (b > 275 && b < 330) serialPort1.Write("6");
                    if (b > 330 && b < 385) serialPort1.Write("5");
                    if (b > 385 && b < 440) serialPort1.Write("4");
                    if (b > 440 && b < 495) serialPort1.Write("3");
                    if (b > 495 && b < 550) serialPort1.Write("2");
                    if (b > 550 && b < 600) serialPort1.Write("1");
                    b = b + 40;
                }
                else
                    label18.Text = "white";
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.PortName = "COM" + textBox1.Text.ToString();
                button1.ForeColor = Color.Green;
                serialPort1.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
Sam I. Ibraheem
 
Posts: 1
Joined: Wed Feb 05, 2014 4:41 pm



Return to Image Processing and Computer Vision