0

I want to detect the rectangles in the red zone of the picture below, I defined the picture center and drew a line and compared my center to the rectangles center and that way I am able to find the centres.

My approach didn't take Y into consideration but the left range requires that. So I think Points would be appropriate to use here but I don't know how to do that,

QUESTION How to define this range(demonstrated by the redlines), I just want to know which objects are on the left line,right line,center line(gray lines), So by defining lines,spaces, anything would work for me,

   // 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

4

1 回答 1

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;
    }
}
于 2013-06-26T21:47:51.970 回答