本文整理汇总了C#中Mat.height方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.height方法的具体用法?C# Mat.height怎么用?C# Mat.height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat.height方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: loadToolStripMenuItem_Click
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
//Get the original img Mat
Mat originalImage = new Mat(openFileDialog1.FileName, LoadImageType.Color);
//Load the original image
imageBox1.Image = originalImage;
//Get gray image
Mat grayImg = new Mat();
CvInvoke.CvtColor(originalImage, grayImg, ColorConversion.Bgr2Gray);
//Create paisage
Mat illustratedImg = gradientFill(new Size(originalImage.width(), originalImage.height()));
//Show gray image
imageBox3.Image = grayImg;
Mat featureImage = originalImage.Clone();
//Run face detector on the image
ArrayList<PersonFace> personFaces = faceDetector.Detect(featureImage);
Mat hairImage = originalImage.Clone();
foreach (PersonFace personFace in personFaces)
{
personFace.Evaluate();
if (!personFace.IsValid())
continue;
drawFaceRectangles(personFace, originalImage.Clone());
detectSkinColor(personFace, originalImage.Clone());
//detectHair(personFace, hairImage);
drawFaceFeatures(personFace, illustratedImg);
//----- Begin Histogram Tests ---------------
/*DenseHistogram hist = new DenseHistogram(256, new RangeF(0, 255));
Image<Gray, byte>[] imgComponents = testImg.Split();
//Get blue components
hist.Calculate(new Image<Gray, byte>[] { imgComponents[0] }, false, null);
float[] blueBins = hist.GetBinValues();
//Get green components
hist.Calculate(new Image<Gray, byte>[] { imgComponents[1] }, false, null);
float[] greenBins = hist.GetBinValues();
//Get red components
hist.Calculate(new Image<Gray, byte>[] { imgComponents[2] }, false, null);
float[] redBins = hist.GetBinValues();
double blueMean = 0;
for (int i = 0; i < blueBins.Length; i++)
{
blueMean += i * blueBins[i];
}
blueMean /= testImg.Width * testImg.Height;
double greenMean = 0;
for (int i = 0; i < greenBins.Length; i++)
{
greenMean += i * greenBins[i];
}
greenMean /= testImg.Width * testImg.Height;
double redMean = 0;
for (int i = 0; i < redBins.Length; i++)
{
redMean += i * redBins[i];
}
redMean /= testImg.Width * testImg.Height;
Scalar skinColor = new Scalar(
Math.Round(blueMean),
Math.Round(greenMean),
Math.Round(redMean));
setColorBox((byte)Math.Round(redMean),
(byte)Math.Round(greenMean),
(byte)Math.Round(blueMean));*/
//MessageBox.Show(redMean + " " + greenMean + " " + blueMean);
/*testImg.ROI = default(System.Drawing.Rectangle);
int[] blueValues = getMinMaxBins(blueBins);
int[] greenValues = getMinMaxBins(greenBins);
int[] redValues = getMinMaxBins(redBins);*/
//.........这里部分代码省略.........
示例2: detectHair
void detectHair(PersonFace personFace, Mat hairImage)
{
Rect faceRect = personFace.GetFace();
double adjWidth = faceRect.width * 0.85;
double adjHeight = faceRect.height * 1.2;
double adjX = faceRect.x + (faceRect.width - adjWidth) / 2;
double adjY = faceRect.y + (faceRect.height - adjHeight) / 2;
Rect adjFaceRect = new Rect((int)adjX, (int)adjY, (int)adjWidth, (int)adjHeight);
double[] faceLineData = personFace.GetFaceLineData();
PointGenerator faceLine = new PointGenerator(faceLineData[0], faceLineData[1]);
Point faceTopPoint = faceLine.GetFromY(adjFaceRect.y);
Point faceBottomPoint = faceLine.GetFromY(adjFaceRect.y + adjFaceRect.height);
//Draw face line
//Imgproc.line(hairImage, faceTopPoint, faceBottomPoint, new Scalar(255, 0, 0), 2);
//Get face feature angle
double faceFeatureAngle = Math.Atan(faceLineData[0]);
faceFeatureAngle = RadianToDegree(faceFeatureAngle);
faceFeatureAngle += faceFeatureAngle > 0 ? -90 : 90;
//Imgproc.rectangle(hairImage, adjFaceRect, new Scalar(0, 255, 255), 2);
/*Imgproc.ellipse(hairImage,
new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
new Size(adjFaceRect.width/2, adjFaceRect.height/2), faceFeatureAngle, 0, 360, new Scalar(255, 0, 0), 2);
Imgproc.ellipse(hairImage,
new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
new Size((int)(adjFaceRect.width / 1.8), (int)(adjFaceRect.height / 1.8)), faceFeatureAngle, 0, 360, new Scalar(255, 0, 0), 2);*/
Mat[] imgComponents = hairImage.Split();
for (int i = 0; i < 5; i++)
{
double factor = 1.8 - i * 0.2;
Mat maskImage = new Image<Gray, byte>(hairImage.width(), hairImage.height(), new Gray(0)).Mat;
Imgproc.ellipse(maskImage,
new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
new Size((int)(adjFaceRect.width / factor), (int)(adjFaceRect.height / factor)), faceFeatureAngle + 180, 0, 180, new Scalar(255), -1);
Imgproc.ellipse(maskImage,
new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
new Size(adjFaceRect.width / 2, adjFaceRect.height / 2), faceFeatureAngle, 0, 360, new Scalar(0), -1);
//imageBox13.Image = maskImage;
Mat testImg = new Mat();
hairImage.CopyTo(testImg, maskImage);
imageBox13.Image = testImg;
Stack<string> titleStack = new Stack<string>();
titleStack.Push("Red");
titleStack.Push("Green");
titleStack.Push("Blue");
HistogramForm histForm = new HistogramForm();
foreach (Mat img in imgComponents)
{
//try histogram only the upper half to detect the most probable hair color range
Mat hist = new Mat();
CvInvoke.CalcHist(new VectorOfMat(img), new int[] { 0 }, maskImage, hist, new int[] { 256 }, new float[] { 0, 255 }, false);
string color = titleStack.Pop();
histForm.AddHist(hist, color, System.Drawing.Color.FromName(color));
/*byte[] testBuffer = new byte[256];
hist.CopyTo(testBuffer);
string msg = "";
foreach (byte value in testBuffer)
msg += value + " ";
msg += Environment.NewLine;
msg += Environment.NewLine;
textBox1.AppendText(msg);*/
}
histForm.Show(i.ToString());
}
Image<Bgr, byte> testImg2 = new Image<Bgr, byte>(hairImage.Bitmap);
imageBox13.Image = testImg2.InRange(new Bgr(25, 25, 25), new Bgr(100, 85, 100));
//createHistogram(new Image<Bgr, byte>(maskImage.Bitmap), 256, "teste");
//.........这里部分代码省略.........
示例3: drawFaceFeatures
void drawFaceFeatures(PersonFace personFace, Mat illustratedImg)
{
Rect faceRect = personFace.GetFace();
Rect mouthRect = personFace.GetMouth();
Rect noseRect = personFace.GetNose();
Rect[] eyesRects = personFace.GetEyes();
//Draw face division line
double[] faceLineData = personFace.GetFaceLineData();
PointGenerator faceLine = new PointGenerator(faceLineData[0], faceLineData[1]);
Point faceTopPoint = faceLine.GetFromY(faceRect.y);
Point faceBottomPoint = faceLine.GetFromY(faceRect.y + faceRect.height);
//Imgproc.line(illustratedImg, faceTopPoint, faceBottomPoint, new Scalar(255, 0, 0), 1);
//Get face feature angle
double faceFeatureAngle = Math.Atan(faceLineData[0]);
faceFeatureAngle = RadianToDegree(faceFeatureAngle);
faceFeatureAngle += faceFeatureAngle > 0 ? -90 : 90;
//Draw face lateral boundaries lines
//Detect right and left eye
Rect rightEye, leftEye;
if (eyesRects[0].x > eyesRects[1].x)
{
rightEye = eyesRects[1];
leftEye = eyesRects[0];
}
else
{
rightEye = eyesRects[0];
leftEye = eyesRects[1];
}
//get eye line generator
PointGenerator eyeLines = new PointGenerator(
getRectCenter(rightEye), getRectCenter(leftEye));
Point leftFacePoint = eyeLines.GetFromX(getRectCenter(leftEye).x + leftEye.width);
Point rightFacePoint = eyeLines.GetFromX(getRectCenter(rightEye).x - rightEye.width);
/* CvInvoke.Circle(image, leftFacePoint, 20,
new Bgr(Color.Green).MCvScalar, -1);
CvInvoke.Circle(image, rightFacePoint, 20,
new Bgr(Color.Blue).MCvScalar, -1);*/
//Get line generators for each side of the face
double faceLineSlope = faceLineData[0];
//Left side
double leftFaceSideOffset = leftFacePoint.y - leftFacePoint.x * faceLineSlope;
PointGenerator leftFaceLine = new PointGenerator(faceLineSlope, leftFaceSideOffset);
Point startPointL = leftFaceLine.GetFromY(0);
Point endPointL = leftFaceLine.GetFromY(illustratedImg.Height);
//Right side
double rightFaceSideOffset = rightFacePoint.y - rightFacePoint.x * faceLineSlope;
PointGenerator rightFaceLine = new PointGenerator(faceLineSlope, rightFaceSideOffset);
Point startPointR = rightFaceLine.GetFromY(0);
Point endPointR = rightFaceLine.GetFromY(illustratedImg.Height);
//Imgproc.line(illustratedImg, startPointL, endPointL, new Scalar(0,255,0), 5);
//Imgproc.line(illustratedImg, startPointR, endPointR,new Scalar(255,0,0), 3);
//Draw mouth line
//Put center on the top for the mouth stay in the middle of the mouth square
Point mouthCenter = new Point(mouthRect.x + mouthRect.width / 2, mouthRect.y);
Size mouthSize = new Size(mouthRect.width / 2, mouthRect.height / 2);
Point mCenter = getRectCenter(mouthRect);
//Get mouth line generator
double aFactMouth = Math.Tan(Math.Atan(faceLineSlope) + Math.PI / 2);
double bfactMouth = mCenter.y - mCenter.x * aFactMouth;
PointGenerator mouthLine = new PointGenerator(aFactMouth, bfactMouth);
double leftFaceMouthCrossX = (bfactMouth - leftFaceSideOffset) /
(faceLineSlope - aFactMouth);
double rightFaceMouthCrossX = (bfactMouth - rightFaceSideOffset) /
(faceLineSlope - aFactMouth);
Point leftFaceMouthCross = mouthLine.GetFromX(leftFaceMouthCrossX);
Point rightFaceMouthCross = mouthLine.GetFromX(rightFaceMouthCrossX);
//Get face top line
double afactTopFace = aFactMouth; //use the mouth line since this uses the same slope
double bfactTopFace = faceTopPoint.y - faceTopPoint.x * afactTopFace;
PointGenerator faceTopLine = new PointGenerator(afactTopFace, bfactTopFace);
double leftTopFaceCrossX = (bfactTopFace - leftFaceSideOffset) /
(faceLineSlope - afactTopFace);
double rightTopFaceCrossX = (bfactTopFace - rightFaceSideOffset) /
(faceLineSlope - afactTopFace);
Point leftTopFaceCross = faceTopLine.GetFromX(leftTopFaceCrossX);
//.........这里部分代码省略.........