Advertisement
Semicolon_Kang

Dice Recognition

Jun 16th, 2015
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1.     private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             WebCam_1 = new Capture(0);
  4.             WebCam_1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 640);
  5.             WebCam_1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 480);
  6.             Application.Idle += Application_Idle;
  7.         }
  8.  
  9.         void Application_Idle(object sender, EventArgs e)
  10.         {
  11.             frame = WebCam_1.QueryFrame();
  12.             Capture_Image.Image = frame;
  13.            
  14.         }
  15.  
  16.         private void button1_Click(object sender, EventArgs e)
  17.         {
  18.             Image<Gray, Byte> GrayImage = frame.Convert<Gray, Byte>();
  19.             CvInvoke.cvShowImage("Gray Image", GrayImage);
  20.  
  21.             Gray BinaryThreshold = new Gray(130);
  22.             Image<Gray, byte> BinaryImage = GrayImage.ThresholdBinary(BinaryThreshold, new Gray(255));
  23.             CvInvoke.cvShowImage("Binary Image", BinaryImage);
  24.  
  25.             CircleF[] cir = BinaryImage.HoughCircles(new Gray(255), new Gray(20), 5, 12, 12, 18)[0];
  26.             int total_points = 0;
  27.             foreach (CircleF ci in cir)
  28.             {
  29.                 BinaryImage.Draw(ci, new Gray(128), 1);
  30.                 total_points++;
  31.             }
  32.             textBox1.Text = total_points.ToString();
  33.             Processed.Image = BinaryImage;
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement