GetSubRect(roi).Convert <bgr,byte =“”>()抛出异常</bgr,>

时间:2012-03-23 11:13:19

标签: c# kinect emgucv

我写了一个代码,用于从Kinect图片中选择一个区域(见下文)。该区域应定义为图片中对象的ROI。该区域的选择有效,但在

Image<Bgr, Byte> roiImage = HandImage1.GetSubRect(roi).Convert<Bgr, Byte>();

程序抛出一个异常,而编译器不接受以下行,我不知道这是否取决于之前行的正确语法。

有人知道会发生什么吗?

private List<MCvBox2D> ProcessHandContoursCheck(Image<Bgr, Byte> IntoImage, Contour<Point> Contours, int MinArea, Point ClickedLocation, Image<Gray, Byte> HandImage1)
    {

        List<Point> centers1 = new List<Point>();                                    
        List<MCvBox2D> minRects1 = new List<MCvBox2D>();                             

        double GrenzeX;
        double GrenzeY;


        while (Contours != null)                                                    
        {

                MCvBox2D minRect = Contours.GetMinAreaRect();                       
                if (Contours.Area >= MinArea)                                       
                {


                    centers1.Add(new Point((int)minRect.center.X, (int)minRect.center.Y)); minRects1.Add(minRect);                                               

                    if (!checkAreaExistanz(Contours.Area))
                           AreaVolumeHand.Add(Contours.Area);                                

                    if (ClickedLocation.X > minRect.center.X)
                        GrenzeX = ClickedLocation.X - minRect.center.X;
                    else
                        GrenzeX = minRect.center.X - ClickedLocation.X;

                    if (ClickedLocation.Y > minRect.center.Y)
                        GrenzeY = ClickedLocation.Y - minRect.center.Y;
                    else
                        GrenzeY = minRect.center.Y - ClickedLocation.Y;


                    DangerB.X= ((int)minRect.center.X - (int)GrenzeX);

                    DangerB.Y = (int)minRect.center.Y - (int)GrenzeY;


                    DangerB.Height= (int)minRect.size.Width + (int)GrenzeX;
                    DangerB.Width = (int)minRect.size.Height+ (int)GrenzeY;


                     Rectangle roi = new Rectangle((int)minRect.center.X - (int)GrenzeX, (int)minRect.center.Y - (int)(GrenzeY), (int)minRect.size.Height + (int)GrenzeY, (int)minRect.size.Width + (int)GrenzeX);




                    Image<Bgr, Byte> roiImage = HandImage1.GetSubRect(roi).Convert<Bgr, Byte>(); //<-----------------------


                    IntoImage.Draw(roiImage, new Bgr(Color.Blue), 2);                            // <----------------------- 

                    // Alternative???

                     Size estimatedSize = new Size((int)minRect.size.Width + (int)GrenzeX, (int)minRect.size.Height + (int)GrenzeY);

                     PointF estimatedCenter = new PointF((float)((int)minRect.center.X - (int)GrenzeX), (float)((int)minRect.center.Y - (int)GrenzeY));


                     Rectangle boostedROI = new MCvBox2D(estimatedCenter, estimatedSize, 0).MinAreaRect();


                     boostedROI.X += DangerB.X;
                     boostedROI.Y += DangerB.Y;

                     IntoImage.Draw(boostedROI, new Bgr(Color.Blue), 2);          


                }

            Contours = Contours.HNext;
        }
        return minRects1;
}

1 个答案:

答案 0 :(得分:0)

据我所知,您需要使用HandImage1.ROI属性而不是HandImage1.GetSubRect(roi)

例如

 Rectangle roi = new Rectangle((int)minRect.center.X - (int)GrenzeX, (int)minRect.center.Y - (int)(GrenzeY), (int)minRect.size.Height + (int)GrenzeY, (int)minRect.size.Width + (int)GrenzeX);
 Image<Bgr, Byte> roiImage = HandImage1.Convert<Bgr, Byte>();
 roiImage.ROI=roi;