예제 #1
0
        private static void TestDrawContours()
        {
            CVImage image = new CVImage(100, 100, CVDepth.Depth8U, 1);

            image.DrawRectangle(new System.Drawing.Rectangle(10, 10, 20, 30), System.Drawing.Color.Red, 3);
            new BitmapViewer(image.ToBitmap()).ShowDialog();
            CVImage res = image.DrawContours();

            new BitmapViewer(res.ToBitmap()).ShowDialog();
        }
예제 #2
0
        void DrawHistogram(PictureBox window, CVHistogram histo, int channelIdx)
        {
            int imageWidth  = window.Width;
            int imageHeight = window.Height;

            int bins     = histo.BinSizes[0];
            int binWidth = imageWidth / bins;

            if (binWidth <= 0)
            {
                binWidth = 1;
            }

            CVPair  minMax      = histo.MinMaxValue;
            CVImage outputImage = new CVImage(imageWidth, imageHeight, CVDepth.Depth8U, 3);

            outputImage.Zero();

            for (int bin = 0; bin < bins; bin++)
            {
                double binValue  = histo[bin];
                byte   level     = (byte)CVUtils.Round(binValue * 255 / minMax.Second);
                byte   binHeight = (byte)CVUtils.Round(binValue * imageHeight / minMax.Second);

                byte[] color = new byte[3];
                color[channelIdx] = (byte)(((double)bin / (double)bins) * 255);

                byte[] markerColor = new byte[3];
                markerColor[channelIdx] = level;

                Color colColor  = Color.FromArgb(color[2], color[1], color[0]);
                Color colMarker = Color.FromArgb(markerColor[2], markerColor[1], markerColor[0]);


                outputImage.DrawRectangle(new Rectangle(bin * binWidth, imageHeight - binHeight, binWidth - 1, binHeight), colColor);
                outputImage.DrawRectangle(new Rectangle(bin * binWidth, imageHeight - binHeight, binWidth - 1, binHeight), colMarker);
                outputImage.DrawRectangle(new Rectangle(bin * binWidth, imageHeight - binHeight, 1, binHeight), colMarker);
            }

            window.Image = outputImage.ToBitmap();
            outputImage.Release();
        }
예제 #3
0
파일: Path.cs 프로젝트: tdck/opencvdotnet
        private void DrawSegmentation(Rectangle rect)
        {
            pointCounter = (pointCounter + 1) % 15;

            if (pointCounter != 0)
            {
                return;
            }

            Point pt = new Point(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);

            if (segPoints.Count > 0)
            {
                segmentationImage.DrawLine(segPoints[segPoints.Count - 1], pt, Color.White);
            }

            segPoints.Add(pt);


            Rectangle rc = new Rectangle(pt, new Size(2, 2));

            segmentationImage.DrawRectangle(rc, Color.Yellow);
        }
예제 #4
0
        void DrawHistogram(PictureBox window, CVHistogram histo, int channelIdx)
        {
            int imageWidth = window.Width;
            int imageHeight = window.Height;

            int bins = histo.BinSizes[0];
            int binWidth = imageWidth / bins;
            if (binWidth <= 0) binWidth = 1;

            CVPair minMax = histo.MinMaxValue;
            CVImage outputImage = new CVImage(imageWidth, imageHeight, CVDepth.Depth8U, 3);
            outputImage.Zero();

            for (int bin = 0; bin < bins; bin++)
            {
                double binValue = histo[bin];
                byte level = (byte)CVUtils.Round(binValue * 255 / minMax.Second);
                byte binHeight = (byte)CVUtils.Round(binValue * imageHeight / minMax.Second);

                byte[] color = new byte[3];
                color[channelIdx] = (byte)(((double)bin / (double)bins) * 255);

                byte[] markerColor = new byte[3];
                markerColor[channelIdx] = level;

                Color colColor = Color.FromArgb(color[2], color[1], color[0]);
                Color colMarker = Color.FromArgb(markerColor[2], markerColor[1], markerColor[0]);

                outputImage.DrawRectangle(new Rectangle(bin * binWidth, imageHeight - binHeight, binWidth - 1, binHeight), Color.White /* colColor */);
                outputImage.DrawRectangle(new Rectangle(bin * binWidth, imageHeight - binHeight, binWidth - 1, 1), colMarker);
                outputImage.DrawRectangle(new Rectangle(bin * binWidth, imageHeight - binHeight, 1, binHeight), colMarker);
            }

            window.Image = outputImage.ToBitmap();
            outputImage.Release();
        }