0

私は画像に描画しようとしています

Graphics g = Graphics.FromImage(BWImage);
        Pen red = new Pen(Color.Red, 2);
        foreach (Blob blob in blobs)
        {
            List<IntPoint> leftPoints, rightPoints, edgePoints = new List<IntPoint>();

            // get blob's edge points
            blobCounter.GetBlobsLeftAndRightEdges(blob,
                 out leftPoints, out rightPoints);

            edgePoints.AddRange(leftPoints);
            edgePoints.AddRange(rightPoints);

            // blob's convex hull
            List<IntPoint> hull = hullFinder.FindHull(edgePoints);

            g.DrawPolygon(red, ToPointsArray(hull));

        }

私はウェブカメラからフレームを取得し、各フレームに対して何らかの処理を行ってからそのコードを実行しましたが、機能しませんでした。デバッグしようとしたところ、次の行が見つかりました

Graphics g = Graphics.FromImage(BWImage);

その後の行を実行することなく、永遠に実行し続けます!
何か助けてください。ありがとう。

これが私のコードです

 private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();

        ProcessImage(bitmap);
    }

および ProcessImage メソッド:

#region Skin Detection
        YCbCrFiltering YCbCrFilter = new YCbCrFiltering();

        YCbCrFilter.Y = new Range(0, 1);
        YCbCrFilter.Cb = new Range(-0.1862745098039216f, 0.0294117647058824f);
        YCbCrFilter.Cr = new Range(0.0137254901960784f, 0.2254901960784314f);
        // apply the filter
        var YCbCrFilteredImage = YCbCrFilter.Apply(bitmap);

        #endregion

        #region GrayScale

        // create grayscale filter (BT709)
        Grayscale Gray_filter = new Grayscale(0.2125, 0.7154, 0.0721);
        // apply the filter
        Bitmap grayImage = Gray_filter.Apply(YCbCrFilteredImage);

        Threshold threshold = new Threshold(50);
        Bitmap BWImage = threshold.Apply(grayImage);

        #endregion

        #region Remove noise
        // create filter
        BlobsFiltering BlobsFilteringfilter = new BlobsFiltering();
        // configure filter
        BlobsFilteringfilter.CoupledSizeFiltering = true;
        BlobsFilteringfilter.MinWidth = 150;
        BlobsFilteringfilter.MinHeight = 150;
        BlobsFilteringfilter.MaxHeight = 600;
        BlobsFilteringfilter.MaxWidth = 600; 
        // apply the filter
        var BWImageFiltered = BlobsFilteringfilter.Apply(BWImage);
        #endregion


        #region Fill Holes
        FillHoles FillHolesfilter = new FillHoles();
        FillHolesfilter.MaxHoleHeight = 50;
        FillHolesfilter.MaxHoleWidth = 50;
        FillHolesfilter.CoupledSizeFiltering = false;
        var BWImageFilteredHoles = FillHolesfilter.Apply(BWImageFiltered);
        #endregion

        #region Contouring

        // process image with blob counter
        BlobCounter blobCounter = new BlobCounter();
        blobCounter.ProcessImage(BWImageFilteredHoles);
        Blob[] blobs = blobCounter.GetObjectsInformation();

        Graphics g = Graphics.FromImage(BWImageFilteredHoles);
        Pen red = new Pen(Color.Red, 2);
        // create convex hull searching algorithm
        GrahamConvexHull hullFinder = new GrahamConvexHull();
foreach (Blob blob in blobs)
        {
            List<IntPoint> AllEdgesPoints = new List<IntPoint>();
            List<IntPoint> leftPoints, rightPoints, edgePoints = new List<IntPoint>();

            // get blob's edge points
            blobCounter.GetBlobsLeftAndRightEdges(blob,
                 out leftPoints, out rightPoints);

            edgePoints.AddRange(leftPoints);
            edgePoints.AddRange(rightPoints);

            // blob's convex hull
            List<IntPoint> hull = hullFinder.FindHull(edgePoints);

            g.DrawPolygon(red, ToPointsArray(hull));
 g.Dispose();

        #endregion

        pictureBox1.Image = grayImage;
        pictureBox2.Image = BWImage;
    }
4

1 に答える 1

0

このコードの周りに表示されていない例外ハンドラはありますか? インデックス付きのピクセル形式で画像を渡しているGraphics.FromImage()ため、例外をスローする必要があります。で画像を返し、それを保持します。Grayscale.Apply()Format8bppIndexedBlobsFiltering.Apply()

Bitmap要するに、 と同じサイズの新しい を作成し、そこからBWImage取得し、新しい画像にGraphicsペイントしてから、ブロブを四角形にする必要があります。BWImage

于 2013-01-04T20:02:35.433 に答える