本文整理汇总了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);
}
示例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);
}