当前位置: 首页>>代码示例>>C#>>正文


C# CvMat.Rectangle方法代码示例

本文整理汇总了C#中CvMat.Rectangle方法的典型用法代码示例。如果您正苦于以下问题:C# CvMat.Rectangle方法的具体用法?C# CvMat.Rectangle怎么用?C# CvMat.Rectangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CvMat的用法示例。


在下文中一共展示了CvMat.Rectangle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawHSHistogram

    // Creates an image from a 2D Histogram (x axis = Hue, y axis = Saturation)
    void DrawHSHistogram(CvHistogram hist)
    {
        // Get the maximum and minimum values from the histogram
        float minValue, maxValue;
        hist.GetMinMaxValue(out minValue, out maxValue);

        int xBins = hist.Bins.GetDimSize(0);  // Number of hue bins (x axis)
        int yBins = hist.Bins.GetDimSize(1);  // Number of saturation bins (y axis)

        // Create an image to visualize the histogram
        int scaleHeight = 5, scaleWidth = 5;
        CvMat hist_img = new CvMat(yBins * scaleHeight, xBins * scaleWidth, TriColorMatrix);
        hist_img.Zero(); // Set all the pixels to black

        double binVal;
        int _intensity;
        for (int h = 0; h < xBins; h++)
        {
            for (int s = 0; s < yBins; s++)
            {

                binVal = Cv.QueryHistValue_2D(hist, h, s);
                _intensity = Cv.Round(binVal / maxValue * 255); // 0 to 255

                // Draw a rectangle (h, s) to (h+1, s+1)  (scaled by window size)
                //  The pixel value is the color of the histogram value at bin (h, s)
                hist_img.Rectangle(Cv.Point(h * scaleWidth, s * scaleHeight),
                    Cv.Point((h + 1) * scaleWidth - 1, (s + 1) * scaleHeight - 1),
                    Cv.RGB(_intensity, _intensity, _intensity),
                    Cv.FILLED);
            }
        }

        Cv.ShowImage("HS Histogram", hist_img);
    }
开发者ID:Titoulion,项目名称:Shoal,代码行数:36,代码来源:VideoCaptureScript.cs

示例2: Draw1DHistogram

    // Creates an image from a 1D Histogram
    void Draw1DHistogram(CvMat _image)
    {
        float channelMax = 255;

        CvHistogram hist1 = CalculateOneChannelHistogram(_image, 0, channelMax);
        CvHistogram hist2 = CalculateOneChannelHistogram(_image, 1, channelMax);
        CvHistogram hist3 = CalculateOneChannelHistogram(_image, 2, channelMax);

        // Get the maximum and minimum values from the histogram
        float minValue, maxValue;
        hist1.GetMinMaxValue(out minValue, out maxValue);

        int hBins = hist1.Bins.GetDimSize(0);  // Number of bins

        // Create an image to visualize the histogram
        int scaleWidth = 3, scaleHeight = 1;
        int histWidth = hBins * imColorChannels * scaleWidth, histHeight = Mathf.FloorToInt(channelMax * scaleHeight);
        CvMat hist_img = new CvMat(histHeight, histWidth, TriColorMatrix);
        hist_img.Zero(); // Set all the pixels to black

        double binVal;
        int _intensity;
        for (int h = 0; h < hBins; h++)
        {

            // Draw Channel 1
            binVal = Cv.QueryHistValue_1D(hist1, h);
            _intensity = Cv.Round(binVal / maxValue * channelMax) * scaleHeight; // 0 to channelMax

            // Draw a rectangle (h, s) to (h+1, s+1)  (scaled by window size)
            //  The pixel value is the color of the histogram value at bin (h, s)
            hist_img.Rectangle(Cv.Point(h * imColorChannels * scaleWidth, histHeight),
                    Cv.Point(h * imColorChannels * scaleWidth + 1, histHeight - _intensity),
                        CvColor.Red, Cv.FILLED);

            // Draw Channel 2
            binVal = Cv.QueryHistValue_1D(hist2, h);
            _intensity = Cv.Round(binVal / maxValue * channelMax) * scaleHeight; // 0 to channelMax

            // Draw a rectangle (h, s) to (h+1, s+1)  (scaled by window size)
            //  The pixel value is the color of the histogram value at bin (h, s)
            hist_img.Rectangle(Cv.Point(h * imColorChannels * scaleWidth + 2, histHeight * scaleHeight),
                    Cv.Point(h * imColorChannels * scaleWidth + 3, histHeight * scaleHeight - _intensity),
                    CvColor.Blue, Cv.FILLED);

            // Draw Channel 3
            binVal = Cv.QueryHistValue_1D(hist3, h);
            _intensity = Cv.Round(binVal / maxValue * channelMax) * scaleHeight; // 0 to channelMax

            // Draw a rectangle (h, s) to (h+1, s+1)  (scaled by window size)
            //  The pixel value is the color of the histogram value at bin (h, s)
            hist_img.Rectangle(Cv.Point(h * imColorChannels * scaleWidth + 4, histHeight * scaleHeight),
                    Cv.Point(h * imColorChannels * scaleWidth + 5, histHeight * scaleHeight - _intensity),
                    CvColor.Green, Cv.FILLED);

        }

        Cv.ShowImage("Histogram", hist_img);
    }
开发者ID:Titoulion,项目名称:Shoal,代码行数:60,代码来源:VideoCaptureScript.cs


注:本文中的CvMat.Rectangle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。