簡體   English   中英

檢測感興趣區域中的物體

[英]Detect objects in an area of interest

我想在下面圖片的紅色區域中檢測矩形,我定義了圖片中心並畫了一條線,將我的中心與矩形中心進行了比較,這樣我就可以找到這些中心。

我的方法沒有考慮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))         
{
}

問題論證

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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM