本文整理汇总了C#中Image.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Image.CopyTo方法的具体用法?C# Image.CopyTo怎么用?C# Image.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.CopyTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: binaryNiBlack
//:::::::::::::::::fin variables::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::Method for make the image binary::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//the binarization is inspired in NiBlanck banarization, but in this case, we use just the average of the image.
//openinOperation() remove the noise of the binarized image, using morphological operation, we use opening.
private Image<Gray, Byte> binaryNiBlack(Image<Gray, Byte> handFrame)
{
int widthFrame = handFrame.Width;
int heigthFrame = handFrame.Height;
int sizeSW = 4;
int sizeSW_w = sizeSW; //Size of the slinding window
int sizeSW_h = sizeSW; //Size of the slinding window
int halfWidth = (int)(Math.Floor((double)sizeSW / 2));
int halfHeigth = (int)(Math.Floor((double)sizeSW / 2));
int binaryWidth = widthFrame + halfWidth * 2;
int binaryHeigth = heigthFrame + halfHeigth * 2;
double k = .6;
Image<Gray, Byte> binaryFrameCalculation = new Image<Gray, Byte>(binaryWidth, binaryHeigth);
binaryFrameCalculation.SetZero();
Rectangle roiHand = new Rectangle(halfWidth, halfHeigth, widthFrame, heigthFrame);
binaryFrameCalculation.ROI = roiHand;
handFrame.CopyTo(binaryFrameCalculation);
binaryFrameCalculation.ROI = Rectangle.Empty;
byte[, ,] byteData = handFrame.Data;
for (int i = halfHeigth; i < heigthFrame + halfHeigth; i++)
{
for (int j = halfWidth; j < widthFrame + halfWidth; j++)
{
Gray media;
MCvScalar desest;
MCvScalar mediaValue;
double threshold;
MCvBox2D roi;
Image<Gray, Byte> imageCalculate = new Image<Gray, Byte>(sizeSW_w, sizeSW_h);
roi = new MCvBox2D(new System.Drawing.Point(j, i), new System.Drawing.Size(sizeSW_w, sizeSW_h), 0);
imageCalculate = binaryFrameCalculation.Copy(roi);
binaryFrameCalculation.ROI = Rectangle.Empty;
imageCalculate.AvgSdv(out media, out desest);
mediaValue = media.MCvScalar;
threshold = mediaValue.v0 + (k * desest.v0);
if (byteData[i - halfHeigth, j - halfWidth, 0] < threshold)
byteData[i - halfHeigth, j - halfWidth, 0] = 255;
else
byteData[i - halfHeigth, j - halfWidth, 0] = 0;
}
}
handFrame.Data = byteData;
return handFrame;
}
示例2: GetImage
public Image<Bgra, byte> GetImage(string text)
{
var textCharacters = text.Select(l => _characters.First(c => c.Character == l)).ToList();
var image = new Image<Bgra, byte>(
1 + textCharacters.Sum(c => Math.Max(c.Width, c.Rectangle.Width)) + textCharacters.Sum(c => c.Offset.X),
textCharacters.Max(c => c.Rectangle.Height) + textCharacters.Max(c => c.Offset.Y),
new Bgra(228, 227, 201, 255));
int x = 1;
foreach (var character in textCharacters)
{
if (character.Character == ' ')
{
x += character.Width;
continue;
}
var targetRect = new Rectangle(
x - character.Offset.X,
character.Offset.Y,
character.Rectangle.Width,
character.Rectangle.Height);
var mask = Bitmap.Copy(character.Rectangle).Convert<Gray, byte>();
var characterImage = new Image<Bgra, byte>(mask.Width, mask.Height);
for (int cy = 0; cy < characterImage.Height; cy++)
{
for (int cx = 0; cx < characterImage.Width; cx++)
{
var alpha = mask[cy, cx].Intensity / 253;
characterImage[cy, cx] = new Bgra(
101 * alpha + (228 * (1 - alpha)),
32 * alpha + (227 * (1 - alpha)),
21 * alpha + (201 * (1 - alpha)),
255);
}
}
characterImage.CopyTo(image.GetSubRect(targetRect));
x += character.Width;
}
return image;
}
示例3: runningCamera
private void runningCamera(object sender, EventArgs e)
{
imageFrameT = captureT.QueryFrame();
if (imageFrameT != null)
{
if(facePosition != null){
if (showedStatus.Equals("..."))
{
Size dialogSize = new Size(300, 100);
Rectangle drawArea = new Rectangle(facePosition, dialogSize);
initialImage = imageFrameT.Copy();
Image<Bgr, Byte> opacityOverlay = new Image<Bgr, byte>(drawArea.Width, drawArea.Height, new Bgr(Color.Black));
initialImage.ROI = drawArea;
opacityOverlay.CopyTo(initialImage);
initialImage.ROI = System.Drawing.Rectangle.Empty;
double alpha = 0.8;
double beta = 1 - alpha;
double gamma = 0;
initialImage.Draw(drawArea, new Bgr(Color.LawnGreen), 2);
initialImage = imageFrameT.AddWeighted(initialImage, alpha, beta, gamma);
}
}
imageBox1.Image = initialImage;
}
}
示例4: runAR
private void runAR(string nameID)
{
Rectangle drawArea = new Rectangle(framePoint, frameSize);
Rectangle drawArea2 = new Rectangle(new Point(framePoint.X+15,framePoint.Y+15), new Size(140, 175));
Image<Bgr, Byte> opacityOverlay = new Image<Bgr, Byte>(drawArea.Width, drawArea.Height, new Bgr(Color.Black));
drawFrame.ROI = drawArea;
opacityOverlay.CopyTo(drawFrame);
drawFrame.ROI = Rectangle.Empty;
double alpha = 0.7;
double beta = 1 - alpha;
double gamma = 0;
drawFrame.Draw(drawArea, new Bgr(Color.Black), 2);
drawFrame = imageFrame.AddWeighted(drawFrame, alpha, beta, gamma);
drawFrame.Draw(drawArea, new Bgr(Color.LimeGreen), 2);
////***********TEXT***********
if (!ARDisplayFlag)
{
if (!nameID.Equals("0"))
{
txtAR = mydb.getUserData(nameID);
}
else
{
txtAR = "Can not recognize any face";
}
Console.WriteLine("loop");
}
Console.WriteLine(txtAR+" "+nameID);
//txtAR = "abc def ghi";
int tmpY = framePoint.Y;
if (!nameID.Equals("0"))
{
string[] txtSet = txtAR.Split(' ');
for (int i = 0; i < txtSet.Length+1; i++)
{
switch (i)
{
case 0:
drawFrame.Draw(" User ID: " + txtSet[i], ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
label9.Text = "User ID: " + txtSet[i];
tmpY += 30;
break;
case 1:
drawFrame.Draw(" Name: " + txtSet[i], ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
label4.Text = "Name: " + txtSet[i];
tmpY += 30;
break;
case 2:
drawFrame.Draw(" Surname: " + txtSet[i], ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
label5.Text = "Surname: " + txtSet[i];
tmpY += 30;
break;
case 3:
drawFrame.Draw(" Birthdate: " + txtSet[i], ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
label7.Text = "Birthdate: " + txtSet[i];
tmpY += 30;
break;
case 4:
break;
case 5:
drawFrame.Draw("Blood group: " + txtSet[i], ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
label6.Text = "Blood group: " + txtSet[i];
tmpY += 30;
break;
case 6:
drawFrame.Draw(" Gender: " + txtSet[i], ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
label8.Text = "Gender: " + txtSet[i];
tmpY += 30;
break;
case 7:
drawFrame.Draw(" Confident: " + Math.Round(confident, 2), ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
tmpY += 30;
break;
default:
break;
}
}
}
else
{
string txtSet = txtAR;
label4.Text = "";
label5.Text = "";
label6.Text = "";
label7.Text = "";
label8.Text = "";
label9.Text = "";
drawFrame.Draw(txtSet, ref font, new Point(framePoint.X + 170, tmpY + 30), new Bgr(Color.LawnGreen));
}
////***********Picture***********
if (!ARDisplayFlag)
{
imgAR = mydb.getResultImage(name);
}
Image<Bgr, Byte> imageSrc = imgAR.Convert<Bgr,byte>();
//.........这里部分代码省略.........
示例5: FloodFill
void FloodFill(Image<Gray, Byte> image, Rectangle roi)
{
image.ROI = roi;
TempMask.ROI = roi;
image.CopyTo(TempMask);
double[] min, max;
Point[] minLoc, maxLoc;
TempMask.MinMax(out min, out max, out minLoc, out maxLoc);
if (max != null && max.Count() > 0 && max[0] > 0) {
Log.DebugFormat("Max = {0}, x = {1}, y = {2}", max[0], maxLoc[0].X, maxLoc[0].Y);
CvInvoke.cvFloodFill(TempMask, maxLoc[0], new MCvScalar(255), new MCvScalar(Diff),
new MCvScalar(Diff), out connectedComp, CONNECTIVITY.FOUR_CONNECTED,
FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
FilterImage(image, TempMask);
}
image.ROI = Rectangle.Empty;
TempMask.ROI = Rectangle.Empty;
}
示例6: determineColourSegments
public List<ColourSegment> determineColourSegments(Image<Bgr, byte> image)
{
Boolean isSignFound = false;
SignNotFound signNotFound = SignNotFound.HSV;
int minimumContourArea = (image.Height*image.Width) > 1000000 ? 1000 : 600;
int minimumSegmentWidth = (image.Height * image.Width) > 1000000 ? 30 : 20;
int minimumSegmentHeight = 30;
Image<Gray, byte> fullBinaryImage = null;
Image<Gray, byte> binaryCrop = null;
Image<Bgr, byte> rgbCrop = null;
List<ColourSegment> colourSegmentList = new List<ColourSegment>();
foreach (SignColour colour in Enum.GetValues(typeof(SignColour)))
{
int minimumAspectRatio = colour == SignColour.RED ? 2 : 3;
isSignFound = false;
signNotFound = SignNotFound.HSV;
do
{
if (signNotFound == SignNotFound.HSV)
{
fullBinaryImage = GetPixelMask("HSV", colour, image);
}
else if (signNotFound == SignNotFound.tryGammaCorrect)
{
Image<Bgr, byte> imageGamma = new Image<Bgr, byte>(image.Width, image.Height);
image.CopyTo(imageGamma);
imageGamma._GammaCorrect(2.2);
fullBinaryImage = GetPixelMask("HSV", colour, imageGamma);
imageGamma.Dispose();
}
// TODO: Check FindContour parameters
using (MemStorage storage = new MemStorage())
{
for (var contour = fullBinaryImage.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, RETR_TYPE.CV_RETR_CCOMP); contour != null; contour = contour.HNext)
{
if (contour.Area > minimumContourArea)
{
isSignFound = true;
Rectangle rect1 = contour.BoundingRectangle;
Rectangle rect = rect1;
if ((rect1.X - 1) > 0 && ((rect1.X + (rect1.Width + 1)) < image.Width) && (rect1.Y - 2) > 0 && ((rect1.Y + (rect1.Height + 2)) < image.Height))
rect = new Rectangle(rect1.X - 1, rect1.Y - 1, rect1.Width + 2, rect1.Height + 2);
int rWidth = rect.Width;
int rHeight = rect.Height;
double aspectRatio = (double)rWidth / (double)rHeight;
if (rWidth > minimumSegmentWidth && rHeight > minimumSegmentHeight && aspectRatio > 1 / (double)minimumAspectRatio && aspectRatio < minimumAspectRatio)//
{
Image<Gray, byte> mask = fullBinaryImage.CopyBlank();
mask.Draw(contour, new Gray(255), -1);
binaryCrop = mask.Copy(rect);
rgbCrop = image.Copy(rect);
colourSegmentList.Add(new ColourSegment(rgbCrop, binaryCrop, contour.ToArray(), colour));
mask.Dispose();
}
}
}
}
if (!isSignFound && signNotFound == SignNotFound.HSV)
{
signNotFound = SignNotFound.tryGammaCorrect;
}
else if (!isSignFound && signNotFound == SignNotFound.tryGammaCorrect)
{
isSignFound = true;
}
} while (!isSignFound);
// Free memory
fullBinaryImage.Dispose();
//if (binaryCrop != null) binaryCrop.Dispose();
//if (rgbCrop != null) rgbCrop.Dispose();
}
return colourSegmentList;
}
示例7: aula2ToolStripMenuItem_Click
private void aula2ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (img == null)
return;
//copy Undo Image
imgUndo = img.Copy();
Image<Gray, float> matrix = ImageClass.GetQuantificationMatrix(true, 100);
Image<Ycc, float> blockYCC;
//TableForm.ShowTableStatic(matrix,"Matriz de Quantificacao");
Image<Ycc, float> imgYCC = img.Convert<Ycc, float>(); //Transformar o espaço de cor RGB para YCbCr
// TODO subsampling
//Para cada bloco de 8x8 pixéis, fazer: (Copy(new rectangle(...) ) )
int Yblocks = (int)Math.Ceiling(img.Height / 8.0);
int Xblocks = (int)Math.Ceiling(img.Width / 8.0);
for (int x = 0; x < Xblocks; x++)
{
for (int y = 0; y < Yblocks; y++)
{
Image<Gray, float> y1 = imgYCC[0].Copy(new Rectangle(x * 8, y * 8, 8, 8));
Image<Gray, float> Cr = imgYCC[1].Copy(new Rectangle(x * 8, y * 8, 8, 8));
Image<Gray, float> Cb = imgYCC[2].Copy(new Rectangle(x * 8, y * 8, 8, 8));
CvInvoke.cvDCT(y1, y1, CV_DCT_TYPE.CV_DXT_FORWARD);//cálculo da transformada de cossenos DCT
CvInvoke.cvDCT(Cb, Cb, CV_DCT_TYPE.CV_DXT_FORWARD);
CvInvoke.cvDCT(Cr, Cr, CV_DCT_TYPE.CV_DXT_FORWARD);
CvInvoke.cvDiv(y1, matrix, y1, 1); // quantificação dos coeficientes
CvInvoke.cvDiv(Cb, matrix, Cb, 1);
CvInvoke.cvDiv(Cr, matrix, Cr, 1);
ImageClass.myRound(y1); //arredondamento dos coeficientes
ImageClass.myRound(Cb);
ImageClass.myRound(Cr);
// DESCOMPRESSÃO
CvInvoke.cvMul(y1, matrix, y1, 1); // recuperação dos coeficientes (Mul)
CvInvoke.cvMul(Cb, matrix, Cb, 1);
CvInvoke.cvMul(Cr, matrix, Cr, 1);
CvInvoke.cvDCT(y1, y1, CV_DCT_TYPE.CV_DXT_INVERSE);//cálculo da transformada inversa de cossenos iDCT (
CvInvoke.cvDCT(Cb, Cb, CV_DCT_TYPE.CV_DXT_INVERSE);
CvInvoke.cvDCT(Cr, Cr, CV_DCT_TYPE.CV_DXT_INVERSE);
imgYCC.ROI = new Rectangle(x * 8, y * 8, 8, 8);
blockYCC = new Image<Ycc, float>(8, 8);
CvInvoke.cvMerge(y1, Cr, Cb, IntPtr.Zero, blockYCC);
blockYCC.CopyTo(imgYCC);
imgYCC.ROI = Rectangle.Empty;
}
}
Image<Bgr, byte> imgfinal = imgYCC.Convert<Bgr, float>().Convert<Bgr, byte>();
ShowIMG.ShowIMGStatic(img, imgfinal);
}
示例8: button10_Click
private void button10_Click(object sender, EventArgs e)
{
Mixedflag = 0;
if (radioButton1.Checked)
{
size = 5;
}
else if (radioButton2.Checked)
{
size = 10;
}
else if (radioButton3.Checked)
{
size = 10;
Mixedflag = 1;
}
var = new Image<Bgr, byte>(path);
if (Mixedflag==0)
{
int hrsize = (var.Height) % (size);
int wrsize = (var.Width) % (size);
Bitmap re = new Bitmap(var.ToBitmap(), var.Width - wrsize, var.Height - hrsize);
var = new Image<Bgr,Byte>(re.Width,re.Height);
var = new Image<Bgr, Byte>(re);
grayvar = new Image<Gray, Byte>(re.Width, re.Height);
grayvar = new Image<Gray, Byte>(re);
imageBox1.Image = var;
imageBox1.Show();
//
progressBar2.Maximum = (grayvar.Height * grayvar.Width) / (size * size);
progressBar2.Visible = true;
progressBar2.Value = 0;
//progressBar1.Visible = true;
Mosaic = new Image<Bgr, Byte>(var.Size);
GMosaic = new Image<Gray, Byte>(grayvar.Size);
if (Isgray == 0)
{
Mosaic = new Image<Bgr, Byte>(var.Size);
var.CopyTo(Mosaic);
}
else
{
GMosaic = new Image<Gray, Byte>(grayvar.Size);
grayvar.CopyTo(GMosaic);
}
if (single == 1)
{
Image<Bgr, Byte> tochange = new Image<Bgr, Byte>(path);
Bitmap bit = new Bitmap(path, true); //Open file
Bitmap resized = new Bitmap(bit, size, size); //Resize file
imageBox1.Image = tochange;
tochange = new Image<Bgr,Byte>(resized);
Mosaic = new Image<Bgr, Byte>(var.Size);
var.CopyTo(Mosaic);
Image<Gray, Byte>[] channels = tochange.Split();
for (int i = 0; i < (grayvar.Height ); i += size)
for (int j = 0; j < grayvar.Width; j += size)
{
progressBar2.Value++;
float amin=1;
float max=1;
Rectangle roi = var.ROI;
var.ROI = new Rectangle(j, i, size, size);
//Sets the region of interest of the image to the abpve by which the image is treated just as that rectangle and nothing else
Bitmap smallbox = var.ToBitmap();
Image<Bgr, float> ismallbox = new Image<Bgr, float>(smallbox);
channels = tochange.Split();
for (int k = 0; k < channels.Length; k++)
{
max = 0;
amin = 300;
for (int a = 0; a < ismallbox.Height; a++)
{
for (int b = 0; b < ismallbox.Width; b++)
{
if ((int)ismallbox.Data[a, b, k] > max)
{
max = (int)ismallbox.Data[a, b, k];
}
if ((int)ismallbox.Data[a, b, k] < amin)
{
amin = (int)ismallbox.Data[a, b, k];
}
}
}
CvInvoke.cvNormalize(channels[k], channels[k], amin, max, Emgu.CV.CvEnum.NORM_TYPE.CV_MINMAX, IntPtr.Zero);
}
Image<Bgr, Byte> n = new Image<Bgr, byte>(channels);
resized = new Bitmap(n.Bitmap, size, size); //Resize file
//.........这里部分代码省略.........
示例9: TestImageDFT
public void TestImageDFT()
{
Image<Gray, float> matA = new Image<Gray, float>("stuff.jpg");
//The matrix to be convoled with matA, a bluring filter
Matrix<float> matB = new Matrix<float>(
new float[,] {
{1.0f/16.0f, 1.0f/16.0f, 1.0f/16.0f},
{1.0f/16.0f, 8.0f/16.0f, 1.0f/16.0f},
{1.0f/16.0f, 1.0f/16.0f, 1.0f/16.0f}});
Image<Gray, float> convolvedImage = new Image<Gray, float>(matA.Size + matB.Size - new Size(1, 1));
Matrix<float> dftA = new Matrix<float>(
CvInvoke.cvGetOptimalDFTSize(convolvedImage.Rows),
CvInvoke.cvGetOptimalDFTSize(convolvedImage.Cols));
matA.CopyTo(dftA.GetSubRect(matA.ROI));
CvInvoke.cvDFT(dftA, dftA, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, matA.Rows);
Matrix<float> dftB = new Matrix<float>(dftA.Size);
matB.CopyTo(dftB.GetSubRect(new Rectangle(Point.Empty, matB.Size)));
CvInvoke.cvDFT(dftB, dftB, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, matB.Rows);
CvInvoke.cvMulSpectrums(dftA, dftB, dftA, Emgu.CV.CvEnum.MUL_SPECTRUMS_TYPE.DEFAULT);
CvInvoke.cvDFT(dftA, dftA, Emgu.CV.CvEnum.CV_DXT.CV_DXT_INVERSE, convolvedImage.Rows);
dftA.GetSubRect(new Rectangle(Point.Empty, convolvedImage.Size)).CopyTo(convolvedImage);
}