本文整理汇总了C#中Image.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# Image.Copy方法的具体用法?C# Image.Copy怎么用?C# Image.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.Copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBGModel
public void TestBGModel()
{
int width = 300;
int height = 400;
Image<Bgr, Byte> bg = new Image<Bgr, byte>(width, height);
bg.SetRandNormal(new MCvScalar(), new MCvScalar(100, 100, 100));
Size size = new Size(width / 10, height / 10);
Point topLeft = new Point((width >> 1) - (size.Width >> 1), (height >> 1) - (size.Height >> 1));
Rectangle rect = new Rectangle(topLeft, size);
Image<Bgr, Byte> img1 = bg.Copy();
img1.Draw(rect, new Bgr(Color.Red), -1);
Image<Bgr, Byte> img2 = bg.Copy();
rect.Offset(10, 0);
img2.Draw(rect, new Bgr(Color.Red), -1);
BGStatModel<Bgr> model1 = new BGStatModel<Bgr>(img1, Emgu.CV.CvEnum.BG_STAT_TYPE.GAUSSIAN_BG_MODEL);
model1.Update(img2);
BGStatModel<Bgr> model2 = new BGStatModel<Bgr>(img1, Emgu.CV.CvEnum.BG_STAT_TYPE.FGD_STAT_MODEL);
model2.Update(img2);
//ImageViewer.Show(model2.Foreground);
//ImageViewer.Show(model1.Background);
}
示例2: CopyImage
public static bool CopyImage(Image image)
{
bool result;
// http://csharphelper.com/blog/2014/09/copy-an-irregular-area-from-one-picture-to-another-in-c/
try
{
IDataObject data;
Bitmap opaqueBitmap;
Bitmap transparentBitmap;
MemoryStream transparentBitmapStream;
data = new DataObject();
opaqueBitmap = null;
transparentBitmap = null;
transparentBitmapStream = null;
try
{
opaqueBitmap = image.Copy(Color.White);
transparentBitmap = image.Copy(Color.Transparent);
transparentBitmapStream = new MemoryStream();
transparentBitmap.Save(transparentBitmapStream, ImageFormat.Png);
data.SetData(DataFormats.Bitmap, opaqueBitmap);
data.SetData(PngFormat, false, transparentBitmapStream);
Clipboard.Clear();
Clipboard.SetDataObject(data, true);
}
finally
{
opaqueBitmap?.Dispose();
transparentBitmapStream?.Dispose();
transparentBitmap?.Dispose();
}
result = true;
}
catch (Exception ex)
{
MessageBox.Show($"Failed to copy image. {ex.GetBaseException(). Message}", "Copy Image", MessageBoxButtons.OK,
MessageBoxIcon.Error);
result = false;
}
return result;
}
示例3: CapturedImage
public CapturedImage(Image<Bgr, Byte> image, DateTime captureTime)
{
DateTime startTime = DateTime.Now;
Image = image;
CaptureTime = captureTime;
Image<Bgr, Byte> playArea = image.Copy(new Rectangle(218, 262, 272, 131));
playArea = SmoothImage(playArea);
playArea = playArea.ThresholdBinary(new Bgr(120, 100, 110), new Bgr(255, 255, 255));
playArea = SmoothImage(playArea);
RedTrack = ExtractRedTrack(playArea);
YellowTrack = ExtractYellowTrack(playArea);
BlueTrack = ExtractBlueTrack(playArea);
GreenTrack = ExtractGreenTrack(playArea);
List<Rectangle> redTrackRectangles = ExtractFeatureRectangles(RedTrack);
List<Rectangle> yellowTrackRectangles = ExtractFeatureRectangles(YellowTrack);
List<Rectangle> blueTrackRectangles = ExtractFeatureRectangles(BlueTrack);
List<Rectangle> greenTrackRectangles = ExtractFeatureRectangles(GreenTrack);
AddNotesFromRectangles(redTrackRectangles, NoteType.Red);
AddNotesFromRectangles(yellowTrackRectangles, NoteType.Yellow);
AddNotesFromRectangles(blueTrackRectangles, NoteType.Blue);
AddNotesFromRectangles(greenTrackRectangles, NoteType.Green);
DrawNotes(Notes.Where(n => n.TrackColor == NoteType.Red).ToList(), ref RedTrack);
DrawNotes(Notes.Where(n => n.TrackColor == NoteType.Yellow).ToList(), ref YellowTrack);
DrawNotes(Notes.Where(n => n.TrackColor == NoteType.Blue).ToList(), ref BlueTrack);
DrawNotes(Notes.Where(n => n.TrackColor == NoteType.Green).ToList(), ref GreenTrack);
TimeSpan elapsedTime = DateTime.Now - startTime;
//Debug.WriteLine("Processing image took {0} ms.",elapsedTime.TotalMilliseconds);
}
示例4: DetectFace
private Bitmap DetectFace(Bitmap faceImage)
{
var image = new Image<Bgr, byte>(faceImage);
var gray = image.Convert<Gray, Byte>();
var haarCascadeFilePath = _httpContext.Server.MapPath("haarcascade_frontalface_default.xml");
var face = new HaarCascade(haarCascadeFilePath);
MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(face, 1.1, 10, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
Image<Gray, byte> result = null;
foreach (MCvAvgComp f in facesDetected[0])
{
//draw the face detected in the 0th (gray) channel with blue color
image.Draw(f.rect, new Bgr(Color.Blue), 2);
result = image.Copy(f.rect).Convert<Gray, byte>();
break;
}
if (result != null)
{
result = result.Resize(150, 150, INTER.CV_INTER_CUBIC);
return result.Bitmap;
}
return null;
}
示例5: ProcessFrame
public void ProcessFrame(int threshold)
{
m_OriginalImage = m_Capture.QueryFrame();
m_ClippedImage = m_OriginalImage.Copy(this.RegionOfInterest);
// Make the dark portions bigger
m_ErodedImage = m_ClippedImage.Erode(1);
//Convert the image to grayscale
m_GrayImage = m_ErodedImage.Convert<Gray, Byte>();
m_BlackAndWhiteImage = m_GrayImage.ThresholdBinaryInv(new Gray(threshold), new Gray(255));
FindRectangles(m_BlackAndWhiteImage);
this.FoundRectangleCount = m_FoundRectangles.Count;
if (this.FoundRectangleCount == m_ImageModel.ExpectedRectangleCount)
{
m_ImageModel.AssignFoundRectangles(m_FoundRectangles);
m_FoundRectanglesImage = CreateRectanglesImage(m_ImageModel.GetInsideRectangles());
}
else
{
m_FoundRectanglesImage = CreateRectanglesImage(m_FoundRectangles);
}
}
示例6: Recognize
public static String Recognize(Image<Gray, byte> source, Rectangle position, int threshold = 2000)
{
Image<Gray, byte> face = source.Copy(position).Resize(200, 200, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, false);
face._EqualizeHist();
if (IsTrained)
{
try
{
FaceRecognizer.PredictionResult ER = faceRecognizer.Predict(face);
if (ER.Label == -1)
{
EigenLabel = "Unknown -1";
EigenDistance = 0;
return EigenLabel;
}
else
{
EigenLabel = labels[ER.Label];
EigenDistance = (float)ER.Distance;
if (threshold > -1) EigenThreshold = threshold;
if (EigenDistance > EigenThreshold) return EigenLabel + " " + EigenDistance.ToString();
else return "Unknown " + EigenDistance.ToString();
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
return "Unknown";
}
示例7: UploadButton_Click
protected void UploadButton_Click(object sender, EventArgs e)
{
try
{
if (!((FileUpload1.PostedFile.ContentType == "image/jpeg") ||
(FileUpload1.PostedFile.ContentType == "image/png") ||
(FileUpload1.PostedFile.ContentType == "image/gif") ||
(FileUpload1.PostedFile.ContentType == "image/bmp"))) throw new Exception("Неизвестный тип файла");
string PhotoFolder = Request.PhysicalApplicationPath + @"\photos\";
if (!Directory.Exists(PhotoFolder)) Directory.CreateDirectory(PhotoFolder);
string extention = Path.GetExtension(FileUpload1.FileName);
string uniqueName = Path.ChangeExtension(FileUpload1.FileName, DateTime.Now.Ticks.ToString());
string upFile = Path.Combine(PhotoFolder, uniqueName + extention);
FileUpload1.SaveAs(upFile);
//Распознование лиц
HaarCascade haarCascade = new HaarCascade(Request.PhysicalApplicationPath + @"\haarcascade_frontalface_alt2.xml");
Image<Bgr, Byte> image = new Image<Bgr, Byte>(upFile);
Image<Gray, Byte> grayImage = image.Convert<Gray, Byte>();
Bitmap srcImage = image.ToBitmap();
var detectedFaces = grayImage.DetectHaarCascade(haarCascade)[0];
foreach (var face in detectedFaces)
{
Image<Bgr, Byte> imFace = image.Copy(face.rect);
//Пикселизация (фактор подобран эмпирически)
//при данном факторе одиноково хорошо пикселизируются и большие и маленькие лица
double factor = 0.02 + (double)10 / (double)face.rect.Height;
imFace = imFace.Resize(factor, 0);
imFace = imFace.Resize(1 / factor, 0);
Bitmap faceBitmap = imFace.ToBitmap();
using (Graphics grD = Graphics.FromImage(srcImage))
{
grD.DrawImage(faceBitmap, new Point(face.rect.Left, face.rect.Top));
}
}
string uniqueName_processed = uniqueName + "_processed";
srcImage.Save(Path.Combine(PhotoFolder, uniqueName_processed + extention));
imgTitle.Visible = true;
Image1.ImageUrl = "photos/" + uniqueName_processed + extention;
}
catch (Exception ex)
{
Session["ErrorMsg"] = ex.Message;
Response.Redirect("~/error.aspx", true);
}
}
示例8: Detection
private void Detection(object r, EventArgs e)
{
currentFrame = grabber.QueryFrame();
currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
DetectFace.Detect(currentFrame, "haarcascade_frontalface_default.xml", faces, out detectionTime);
foreach (Rectangle face in faces)
{ //result = currentFrame.Copy(face.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
currentFrame.Draw(face, new Bgr(Color.Red), 2);
//Get copy of img and show it
result = currentFrame.Copy(face).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC); //making small copy of face
result._EqualizeHist();
if (Eigen_Recog.IsTrained)
{
string name = Eigen_Recog.Recognise(result);
//Draw the label for each face detected and recognized
currentFrame.Draw(name, ref font, new Point(face.X - 2, face.Y - 2), new Bgr(Color.LightGreen));
}
}
//display the image
ImageViewer.Image = currentFrame;
labelTimeSpend.Text = detectionTime.ToString() + "msec";
faces.Clear();
currentFrame.Dispose();
}
示例9: DetectAndTrimFace
public static Image<Gray, byte> DetectAndTrimFace(int[] pixels, Size initialSize, Size outputSize, String haarcascadePath)
{
var inBitmap = ConvertToBitmap(pixels, initialSize.Width, initialSize.Width);
//for testing purposes I can the picture to a folder
//inBitmap.Save(@"E:\data\phototest\received.bmp");
var grayframe = new Image<Gray, byte>(inBitmap);
var haar = new HaarCascade(haarcascadePath);
var faces = haar.Detect(grayframe,
1.2,
3,
HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(30, 30));
if (faces.Count() != 1)
{
return null;
}
var face = faces[0];
var returnImage = grayframe.Copy(face.rect).Resize(outputSize.Width, outputSize.Height, INTER.CV_INTER_CUBIC);
//cleanup managed resources
haar.Dispose();
grayframe.Dispose();
return returnImage;
}
示例10: foreach
/// <summary>
/// Draw rectangles on the ResultImage.
/// </summary>
/// <returns>The image with overlayed rectangles.</returns>
/*public void DrawRectanglesOnImage()
{
ResultImage = BaseImage.Copy();
foreach (var rectangle in this.rectangles)
{
ResultImage.Draw(rectangle, new Bgr(Color.Red), 1);
}
}*/
public IDictionary<object, Rectangle[]> FindAllMatches(Image<Bgr, Byte> source, string match = "", bool copy = true, string ignore = "") // todo: proper order
{
var matches = new ConcurrentDictionary<object, Rectangle[]>();
Image<Bgr, Byte> sourceImage = copy ? source.Copy() : source;
foreach (KeyValuePair<object, Image<Bgr, Byte>> subImageKeyValuePair in SubImages)
{
if (match.Length > 0 && !subImageKeyValuePair.Key.ToString().Contains(match)) continue;
if (ignore.Length > 0 && subImageKeyValuePair.Key.ToString().Contains(ignore)) continue;
Rectangle[] subImageMatches = FindMatches(sourceImage, subImageKeyValuePair.Value, copy);
matches[subImageKeyValuePair.Key] = subImageMatches;
}
/*Parallel.ForEach(SubImages, (subImageKeyValuePair) =>
{
if (match.Length > 0 && !subImageKeyValuePair.Key.ToString().Contains(match)) return;
if (ignore.Length > 0 && subImageKeyValuePair.Key.ToString().Contains(ignore)) return;
Rectangle[] subImageMatches = FindMatches(sourceImage, subImageKeyValuePair.Value, copy);
matches[subImageKeyValuePair.Key] = subImageMatches;
//matches.Add(subImageKeyValuePair.Key, subImageMatches);
});*/
return matches;
}
示例11: Detect
public Word Detect(Face face, Image<Bgr, byte> cleanImage)
{
var loginImagesPaths = new List<string>();
if (Directory.Exists(this.usersPath))
loginImagesPaths = Directory.GetFiles(this.usersPath, "*" + this.gesturesPattern, SearchOption.AllDirectories).ToList();
loginImagesPaths = loginImagesPaths.Where(x => x.Contains(this.loginService.CurrentUser)).ToList();
if (!loginImagesPaths.Any())
{
return new Word(string.Empty);
}
else
{
if (this.shouldReloadImages)
{
this.shouldReloadImages = false;
}
var source = cleanImage.Copy();
source.ROI = new Rectangle
{
X = face.Zone.X,
Y = face.Zone.Y,
Width = face.Zone.Width + face.Zone.Width / 3,
Height = face.Zone.Height + face.Zone.Height / 3
};
for (double scale = 1.2; scale > 0.4; scale = scale - 0.1)
{
foreach (var loginPath in loginImagesPaths)
{
var template = new Image<Bgr, byte>(loginPath);
var path = new String(loginPath.ToArray());
Image<Gray, float> result = source.Convert<Gray, byte>().SmoothGaussian(5)
.MatchTemplate(template.Convert<Gray, byte>()
.Resize(scale, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR).SmoothGaussian(5),
Emgu.CV.CvEnum.TM_TYPE.CV_TM_CCOEFF_NORMED);
double[] minValues, maxValues;
Point[] minLocations, maxLocations;
result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
if (maxValues[0] > 0.9)
{
var newPath = path.Replace("\\", "|");
var splittedPath = newPath.Split('|');
if (face.Mouth.IsEmpty)
face.Mouth = new Mouth();
face.Mouth.Word = new Word(splittedPath[splittedPath.Length - 2]);
return face.Mouth.Word;
}
}
}
}
return new Word(string.Empty);
}
示例12: ImageUtils
public ImageUtils(Image<Bgr, Byte> image)
{
originalImage = image.Copy();
vBoundary = new Rectangle(new Point(0, 0), new Size(140, originalImage.Height));
hBoundary = new Rectangle(new Point(0, originalImage.Height - 120), new Size( originalImage.Width, 110));
idBoundary = new Rectangle(new Point(1255, 155), new Size(333, 550 ));
answerBoundary = new Rectangle(new Point(158, 809), new Size(1422, 1394));
}
示例13: Process
public Image<Gray, byte> Process(Image<Gray, byte> src)
{
int width = src.Width, height = src.Height;
if (Padding > 0) {
var rect = new Rectangle(Padding, Padding, width - Padding - Padding, height - Padding - Padding);
return src.Copy(rect);
} else {
int l = 0, r = width - 1, t = 0, b = height - 1;
bool findL = false, findR = false, findT = false, findB = false;
#region 找最左
while (l < width && !findL) {
for (int i = 0; i < height; ++i) {
if (src[i, l].Intensity > 0) {
findL = true;
break;
}
}
l++;
}
#endregion
#region 找最右
while (r >= 0 && !findR) {
for (int i = 0; i < height; ++i) {
if (src[i, r].Intensity > 0) {
findR = true;
break;
}
}
r--;
}
#endregion
#region 找最上
while (t < height && !findT) {
for (int j = 0; j < width; ++j) {
if (src[t, j].Intensity > 0) {
findT = true;
break;
}
}
t++;
}
#endregion
#region 找最下
while (b >= 0 && !findB) {
for (int j = 0; j < width; ++j) {
if (src[b, j].Intensity > 0) {
findB = true;
break;
}
}
b--;
}
#endregion
var rect = new Rectangle(l, t, r - l + 1, b - t + 1);
return src.Copy(rect);
}
}
示例14: JanelaDetectarFace
public JanelaDetectarFace(Mat pImagem)
{
InitializeComponent();
mImagem = pImagem;
// currentFrame = new Image<Bgr, byte>(new Size(320, 240));
// CvInvoke.Resize(mImagem, currentFrame, new Size(320, 240), 0, 0, Emgu.CV.CvEnum.Inter.Cubic);
// imagemDetect.Image = currentFrame.ToBitmap();
if (Eigen_Recog.IsTrained)
{
// message_bar.Text = "Training Data loaded";
}
else
{
//message_bar.Text = "No training data found, please train program using Train menu option";
}
currentFrame = new Image<Bgr, byte>(new Size(820, 780));
CvInvoke.Resize(mImagem, currentFrame, new Size(820, 780), 0, 0, Emgu.CV.CvEnum.Inter.Cubic);
//Convert it to Grayscale
if (currentFrame != null)
{
gray_frame = currentFrame.Convert<Gray, Byte>();
//Face Detector
Rectangle[] facesDetected = Face.DetectMultiScale(gray_frame, 1.2, 10, new Size(50, 50), Size.Empty);
//Action for each element detected
for (int i = 0; i < facesDetected.Length; i++)// (Rectangle face_found in facesDetected)
{
//This will focus in on the face from the haar results its not perfect but it will remove a majoriy
//of the background noise
facesDetected[i].X += (int)(facesDetected[i].Height * 0.15);
facesDetected[i].Y += (int)(facesDetected[i].Width * 0.22);
facesDetected[i].Height -= (int)(facesDetected[i].Height * 0.3);
facesDetected[i].Width -= (int)(facesDetected[i].Width * 0.35);
result = currentFrame.Copy(facesDetected[i]).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.Inter.Cubic);
result._EqualizeHist();
//draw the face detected in the 0th (gray) channel with blue color
currentFrame.Draw(facesDetected[i], new Bgr(Color.Red), 2);
if (Eigen_Recog.IsTrained)
{
string name = Eigen_Recog.Recognise(result);
int match_value = (int)Eigen_Recog.Get_Eigen_Distance;
//Draw the label for each face detected and recognized
currentFrame.Draw(name + "", new Point(facesDetected[i].X - 2, facesDetected[i].Y - 2), Emgu.CV.CvEnum.FontFace.HersheyDuplex, 1, new Bgr(Color.LightGreen));
// currentFrame.Draw(name + " ", ref font, new Point(facesDetected[i].X - 2, facesDetected[i].Y - 2), new Bgr(Color.LightGreen));
// ADD_Face_Found(result, name, match_value);
}
}
//Show the faces procesed and recognized
imagemDetect.Image = currentFrame.ToBitmap();
}
}
示例15: DetectRighEye
//same as DetectLeftEye. Only looking on half-right part of the image
private static bool DetectRighEye(Image<Gray, byte> image)
{
image = image.Copy(new Rectangle(image.Width / 2, 0, image.Width / 2, image.Height));
Rectangle[] result = eyeClassifier.DetectMultiScale(image, 1.1, 3, new Size(20, 20), Size.Empty);
if (result.Length >= 1)
return true;
else
return false;
}