2013-06-26 154 views
0

我想检测下面图片中的红色区域的矩形区域的对象,我所定义的图片中心,画了一条线,比较我中心到矩形中心,这样我能够找到中心。检测感兴趣

我的做法没有考虑Y考虑考虑,但左侧的范围要求。所以我认为Points适合在这里使用,但我不知道该怎么做,

问题如何定义这个范围(用红线表示),我只想知道哪些对象在左边线上,右线,中线(灰线),所以,通过定义行,空格,任何将工作对我来说,

// Rectangles am interested in, have left, right, top, bottom pixel position 
    var rectangleCenter =(left + right)/2; 

if (rectangleCenter >= (CenterRef - 50) && rectangleCenter <= (CenterRef + 50)) 
{ 
} 

// assuming 5 is the curve 
for(int i=0; i<somelimit; i+5) 
{ 
var rectangleCenter = (left + right)/2; 

// assuming its a 1000 pixel image, Mycenter is 500, 
leftRef = MyCenter + 250;   
leftRef + i; 

if (rectangleCenter >= (leftRef - 50) && rectangleCenter <= (leftRef + 50))   
{ 
} 

Problem Demonstration

+0

你介意解释更多!并请彰显你想要的图片(我很抱歉,但我无法理解清楚,对不起:() – 2013-06-26 20:03:51

+0

的红线是我感兴趣区域进行检测,我想检测长方形不到他们, – TrackmeifYouCan

+0

让您随心所欲以检测会发生这些行线(黑色)?或矩形? – 2013-06-26 20:10:37

回答

1
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     double[,] allPoints = new double[5, 3]; //Each rectangle is defined by 4 X/Y Points (left-top, left-bottom, right-top and right-bottom) 

     //The four points of each rectangle have to be inside the given area (inside the given couple of red lines) 
     int foundInArea = 0; 
     int areaCount = 0; 
     do 
     { 
      areaCount = areaCount + 1; //There are three areas; what is inside each couple of two red lines 

      foundInArea = areaCount; 
      int count1 = 0; 
      do 
      { 
       count1 = count1 + 1; 
       if (!isInArea(areaCount, new double[] { 0, allPoints[count1, 1], allPoints[count1, 2] })) 
       { 
        foundInArea = 0; 
        break; 
       } 
      } while (count1 < 4); 

      if (foundInArea > 0) 
      { 
       break; 
      } 
     } while (areaCount < 3); 

     if (foundInArea > 0) 
     { 
      //Rectangle inside are foundInArea 
     } 
    } 

    private bool isInArea(int areaNo, double[] pointToTest) 
    { 
     bool isThere = false; 

     double alpha = returnAngles(areaNo); //Inclination of the red lines 
     double[] startPoint1 = returnStartEndPoints(areaNo, true, true); //Initial point of the red line on the left 
     double[] endPoint1 = returnStartEndPoints(areaNo, true, false); //End point of the red line on the left 
     double[] startPoint2 = returnStartEndPoints(areaNo, false, true); //Initial point of the red line on the right 
     double[] endPoint2 = returnStartEndPoints(areaNo, false, false); //End point of the red line on the right 

     return checkPoint(pointToTest, alpha, startPoint1, endPoint1, startPoint2, endPoint2); 
    } 

    private bool checkPoint(double[] pointToTest, double alpha, double[] startPoint1, double[] endPoint1, double[] startPoint2, double[] endPoint2) 
    { 
     bool isThere = false; 

     //You have all the information and can perform the required trigonometrical calculculations to determine whether the two lines surround the given point or not 
     //I think that I have worked more than enough in this code :) 

     return isThere; 
    } 

    //Hardcoded angles for each red line. 
    //All the angles have to be taken from the same reference point (for example: middle-bottom part) 
    //Example: area1 (lines on the left): 240 degree, area2: 270 degree... 
    private double returnAngles(int areaNo) 
    { 
     double outVal = 0; 
     if (areaNo == 1) 
     { 
      //outVal = val; 
     } 
     else if (areaNo == 2) 
     { 
      //outVal = val; 
     } 
     else if (areaNo == 3) 
     { 
      //outVal = val; 
     } 

     return outVal; 
    } 
    //Returning the X (index 1) and Y (index 2) values under the given conditions (start/end point for each area) 
    //These values have to be hardcoded from a rough estimation. For example, by assuming that the start is in the upper part, 
    //the starting point for the left line can be assumed to be X = max_X/3 and Y = max_Y 
    private double[] returnStartEndPoints(int areaNo, bool isLeftLine, bool isStartPoint) 
    { 
     double[] outPoint = new double[3]; 

     if (areaNo == 1) 
     { 
      if (isLeftLine) 
      { 
       if (isStartPoint) 
       { 
        //outPoint[1] = value; //hardcoded X for start point of line on the left of area1 
        //outPoint[2] = value; //hardcoded Y for start point of line on the left of area1 
       } 
       else 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
      } 
      else 
      { 
       if (isStartPoint) 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
       else 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
      } 
     } 
     else if (areaNo == 2) 
     { 
      if (isLeftLine) 
      { 
       if (isStartPoint) 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
       else 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
      } 
      else 
      { 
       if (isStartPoint) 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
       else 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
      } 
     } 
     else if (areaNo == 3) 
     { 
      if (isLeftLine) 
      { 
       if (isStartPoint) 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
       else 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
      } 
      else 
      { 
       if (isStartPoint) 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
       else 
       { 
        //outPoint[1] = value; 
        //outPoint[2] = value; 
       } 
      } 
     } 

     return outPoint; 
    } 
} 
+0

我会读这个,并希望你在这里几分钟后,如果我发现任何东西,这是非常有帮助的,不管! – TrackmeifYouCan

+0

正如你所看到的那样,你可以在这里找到所有需要的地方:你可以在下面的地方硬编码所有需要的点(returnAngles和returnStartEndPoints)。在Form1_Load中,您必须介绍定义每个矩形的4个点,checkPoint是所有calc必须完成的地方(我什么都没有)。 – varocarbas

+0

我相信这很有帮助:这是解决这个问题的主要框架(在当前几何体或其他任何几何体下)。我认为你没有太清楚的想法,因此我宁愿花一点时间给你一个适当的帮助(尽管我不打算花这么多钱)。我做得比较快,因此,如果你看到一个bug或任何东西,只是忽略它:)我会在这里为你而不是太久。 – varocarbas