Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
public partial class Form1 : Form
    {
        static Bitmap img;      
      
        private void timer1_Tick(object sender, EventArgs e)
        {
            Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) + @"C:\new\Pranay\ScreenCaptures");        
 
            if (!string.IsNullOrEmpty(axWindowsMediaPlayer1.URL))
            {               
                Image ret = null;
                try
                {
 
//--------------------------------------------------- take picture BEFORE saveFileDialog pops up!!-----------------------------------------------------
                    Bitmap bitmap = new Bitmap(axWindowsMediaPlayer1.Width, axWindowsMediaPlayer1.Height);
 
                    //EuclideanColorFiltering filter = new EuclideanColorFiltering();
                    //filter.CenterColor = Color.FromArgb(215, 30, 30);
                    //filter.Radius = 100;
                    //filter.ApplyInPlace(bitmap);

                    //    newPicBox.Image = bitmap;

                    {
                        Graphics g = Graphics.FromImage(bitmap);
                        {
                            Graphics gg = axWindowsMediaPlayer1.CreateGraphics();
                            {
                                FrameTimer.Start();
                                this.BringToFront();
                                g.CopyFromScreen(axWindowsMediaPlayer1.PointToScreen(new System.Drawing.Point()).X, axWindowsMediaPlayer1.PointToScreen(new System.Drawing.Point()).Y, 0, 0, new System.Drawing.Size(axWindowsMediaPlayer1.Width, axWindowsMediaPlayer1.Height - 60));
 
                                FramepictureBox.Image = bitmap;
 
                                //Change the color of the pixel=-------------------Image comparing--------------------------------------------------

                                Bitmap img1 = bitmap;
                                if (img != null)
                                {
 
                                    float avg = 0;
                                    float avg1 = 0;
 
                                    if (img1.Width == img.Width && img1.Height == img.Height)
                                    {
                                        for (int i = 170; i < 296; i++)
                                        {
                                            for (int j = 70; j < 100; j++)
                                            {
                                                // img1.SetPixel(i, j, Color.Red);
                                                Color img1_ref = img1.GetPixel(i, j);
                                                Color img2_ref = img.GetPixel(i, j);
                                                float oneR = img1_ref.R;
                                                float twoR = img2_ref.R;
                                                float diffR = Math.Abs(oneR - twoR);
 
                                                float oneG = img1_ref.G;
                                                float twoG = img2_ref.G;
                                                float diffG = Math.Abs(oneG - twoG);
                                                float oneB = img1_ref.B;
                                                float twoB = img2_ref.B;
                                                float diffB = Math.Abs(oneB - twoB);
                                                float perR = (diffR / 255) * 100;
                                                float perG = (diffG / 255) * 100;
                                                float perB = (diffB / 255) * 100;
                                                float netPer = (perB + perG + perR) / 3;
                                                avg += netPer;
                                            }
                                        }
                                        /*-------------------------------------------Second Rectangle----------------------------------------------*/
 
                                      same as above but change i Co-ordinates
 

                                        int totalPixels = 161 * 50;
 
                                        int totalPixels1 = 20 * 166;
 
                                        float netAvg = avg / totalPixels;
                                        float netAvg1 = avg1 / totalPixels1;
 
                                        RGBlbl.Text = netAvg1.ToString();
                                        RGBlbl1.Text = netAvg.ToString();
 
                                        if (netAvg > 0.5)
                                        {
                                            if (netAvg1 > 2)
                                            {
                                              
                                                Pen pen = new Pen(Color.Red, 1);
                                                g.DrawRectangle(pen, 50, 120, 161, 50);
                                                using (MemoryStream ms = new MemoryStream())                                                {
                                                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                                    ret = System.Drawing.Image.FromStream(ms);
 
                                                    ret.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) + @"C:\new\Pranay\ScreenCaptures\" + "IMG" + i + ".jpeg", ImageFormat.Jpeg);
 
                                                }
                                                i++;
                                                ImageConverter converter = new ImageConverter();
                                                byte[] imgbit = (byte[])converter.ConvertTo(img1, typeof(byte[]));
 

                                                string strcon = "Data Source=U8-PC\\SQLEXPRESS;Initial Catalog=TrafficAnalysis;Integrated Security=true";
                                                SqlConnection mycon = new SqlConnection(strcon);
                                                mycon.Open();
                                                string strquery = "insert into Image(ImageData) values('" + imgbit + "')";
                                                SqlCommand cmd = new SqlCommand(strquery, mycon);
                                                cmd.ExecuteNonQuery();
                                            }
                                        }
                                        else
                                        {
 
                                        }
                                    }
                                }
                            }
                        }
                        //  afterwards save bitmap file if user wants to
                        img = bitmap;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
Posted 11-Jan-13 20:22pm
Edited 11-Jan-13 20:45pm
(no name)499K
v2
Comments
Sandeep Mewara at 12-Jan-13 1:45am
   
What is the issue with the code?
OriginalGriff at 12-Jan-13 2:16am
   
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
ridoy at 12-Jan-13 5:27am
   
Then what do we understand from your code?
tiggerc at 14-Jan-13 11:25am
   
Looking at the code it looks like you are attempting to compare a previous image with the current image and then determine if the changes are a car?
 
Not my area of expertise really, but it looks like it could have a few issues.
 
Working out what is a Vehicle ( not a tree moving )
 
but if you could better form your question we may be able to help some more.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 424
1 ridoy 400
2 DamithSL 230
3 OriginalGriff 179
4 Suvendu Shekhar Giri 150
0 OriginalGriff 8,033
1 DamithSL 6,179
2 Sergey Alexandrovich Kryukov 5,538
3 Maciej Los 5,508
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100