Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Emgu.CV.Structure;
  11. using Emgu.Util;
  12. using Emgu.CV;
  13. using Emgu.CV.Util;
  14.  
  15.  
  16. namespace Lab9
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.         Capture cp;
  25.  
  26.  
  27.         private void button1_Click(object sender, EventArgs e)
  28.         {
  29.             cp = new Capture(@"D:\filmik.avi");
  30.            
  31.  
  32.             cp.ImageGrabbed += Pobierz;
  33.             cp.Start();
  34.         }
  35.         public void Pobierz (object o,EventArgs e)
  36.         {
  37.             Mat obraz = new Mat();
  38.             Mat obraz1 = new Mat();
  39.             Mat obraz2 = new Mat();
  40.             cp.Retrieve(obraz);
  41.             System.Threading.Thread.Sleep(40);
  42.             Image<Bgr, double> jakis_obraz = obraz.ToImage<Bgr, double>();
  43.             double[, ,] dane = jakis_obraz.Data;
  44.             for (int y = 0; y < jakis_obraz.Height; y++)
  45.                 for (int x = 0; x < jakis_obraz.Width; x++)
  46.                 {
  47.                     double G = dane[y, x, 1];
  48.                     dane[y, x, 0] = dane[y, x, 1] = dane[y, x, 2] = G;
  49.                 }
  50.  
  51.  
  52.  
  53.             Mat jakis_obraz1 = new Mat();
  54.             Mat obraz10 = CvInvoke.CvArrToMat(jakis_obraz);
  55.             Mat obraz4 = new Mat();
  56.             obraz10.ConvertTo(obraz4, Emgu.CV.CvEnum.DepthType.Cv8U);
  57.             CvInvoke.Canny(obraz4, jakis_obraz1, 400, 50, 3, false);
  58.             VectorOfVectorOfPoint kontury = new VectorOfVectorOfPoint();
  59.             Mat hierarchia = new Mat();
  60.             CvInvoke.FindContours(jakis_obraz1,kontury,hierarchia,Emgu.CV.CvEnum.RetrType.List,
  61.                 Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
  62.             double A=0;
  63.             double b;
  64.             for (int i = 0; i < kontury.Size; i++)
  65.             {
  66.                 if (CvInvoke.ContourArea(kontury[i]) > A) A = CvInvoke.ContourArea(kontury[i]);
  67.                 if (CvInvoke.ContourArea(kontury[i]) == A)
  68.                     imageBox2.Image = jakis_obraz1;
  69.             }
  70.             imageBox1.Image = obraz;
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement