2015-06-22 75 views
2

這是一個函數,用於確定點是否位於圖像的邊界內,並檢查它是否與其他圓形重疊。使用C#進行光學標記識別

如果它返回true,那麼我檢查填充黑色圓圈的閾值,然後將填充超過90%的點保存到點列表中。

我的程序分兩步工作

1)如果形成沒有overlaping一個圓。

2)如果它已填滿90%。

我正面臨着一個錯誤,如果我只通過一個圖像只有一個圓圈,它可以節省1408個圈子。我不知道我做錯了什麼。

下面是按鈕點擊事件

 for (int i = 0; i < 50; i++) 
     { 
      for (int j = 0; j < 50; j++) 
      { 
       p.X = j; 
       p.Y = i; 
       if (isCircle(p)) 
       { 

        if (checkThreshold(p) > 90) 
        { 
         pts.Insert(0, p); 
        } 
       } 
      } 
     } 

下面給出的是功能

private bool isCircle(Point p) 
    { 

     double count = 0; 
     Point curP = new Point(); 
     //Point centre = new Point(24, 20); 
     int a = 0; 

     boundary.X = 50; 
     boundary.Y = 50; 

     for (int x = (p.X - radius); x <= (p.X - radius); x++) 
     { 
      for (int y = (p.Y - radius); y <= (p.Y - radius); y++) 
      { 
       if ((x < boundary.X) && (y < boundary.Y) && (x + radius < boundary.X) && (y + radius < boundary.Y)) 
       { 
        curP.X = 0; 
        curP.Y = 0; 

        curP.X = x; 
        curP.Y = y; //stores new point to be sent in curP 
        while (a < pts.Count) 
        { 
         //point , centre, radius 
         if (checkOverlap(curP, pts[a], radius) == false) //send point to check if it overlaps or not 
         { 
          // MessageBox.Show("yellow"); 
          count = 1; 
          break; 
         } 
         else 
         { 
          a++; 
         } 

        } 

       } 
       if (count == 1) 
        break; 
      } 
      if (count == 1) 
       break; 

     } 

     if (count == 1) 
      return true; 

     else return false; 
    } 

下面給出的是checkOverlap功能

private bool checkOverlap(Point p, Point c, int radii) 
    { 

     Point listPoint; 

     listPoint = p; 

     //the following if condition checks if the point resides in the list or not 

     if ((((c.X - radii) < listPoint.X) && (listPoint.X > (c.X - radii))) && (((c.Y - radii) < listPoint.Y) && (listPoint.Y > (c.Y - radii)))) 
     { 
      if ((((p.X - c.X) * (p.X - c.X)) - ((p.Y - c.Y) * (p.Y - c.Y))) < (radius * radius)) 
      { 
       return false; 
      } 
      return true; 
     } 
     else 
      return true; 
    } 

回答

0

不知道如果是這樣的問題,但你的count變量應該是int到期到你測試平等的方式。