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


C# Image.Convert方法代码示例

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


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

示例1: Detect_objects

        private bool Detect_objects(Image<Gray, Byte> Input_Image, Image<Gray, Byte> object_Image)
        {
            Point dftSize = new Point(Input_Image.Width + (object_Image.Width * 2), Input_Image.Height + (object_Image.Height * 2));
            bool Success = false;
            using (Image<Gray, Byte> pad_array = new Image<Gray, Byte>(dftSize.X, dftSize.Y))
            {
                //copy centre
                pad_array.ROI = new Rectangle(object_Image.Width, object_Image.Height, Input_Image.Width, Input_Image.Height);
                CvInvoke.cvCopy(Input_Image.Convert<Gray, Byte>(), pad_array, IntPtr.Zero);
               // CvInvoke.cvMatchTemplate
                //CvInvoke.cvShowImage("pad_array", pad_array);
                pad_array.ROI = (new Rectangle(0, 0, dftSize.X, dftSize.Y));
                using (Image<Gray, float> result_Matrix = pad_array.MatchTemplate(object_Image, TM_TYPE.CV_TM_CCOEFF_NORMED))
                {
                    result_Matrix.ROI = new Rectangle(object_Image.Width, object_Image.Height, Input_Image.Width, Input_Image.Height);

                    Point[] MAX_Loc, Min_Loc;
                    double[] min, max;
                    result_Matrix.MinMax(out min, out max, out Min_Loc, out MAX_Loc);

                    using (Image<Gray, double> RG_Image = result_Matrix.Convert<Gray, double>().Copy())
                    {
                        //#TAG WILL NEED TO INCREASE SO THRESHOLD AT LEAST 0.8...used to have 0.7

                        if (max[0] > 0.85)
                        {
                            Object_Location = MAX_Loc[0];
                            Success = true;
                        }
                    }

                }
            }
            return Success;
        }
开发者ID:juanluislm,项目名称:TeamVis,代码行数:35,代码来源:FFT.cs

示例2: FacialDetection

        public Image<Gray, byte> FacialDetection(Image<Gray, byte> Frame)
        {
            StreamReader SR = new StreamReader("CVConfig.txt");
            int width = int.Parse(SR.ReadLine().Split(':')[1]);
            int height = int.Parse(SR.ReadLine().Split(':')[1]);
            Image<Gray, byte> Img = Frame.Convert<Gray, byte>();
            using (Frame)
            {
                if (Frame != null)
                {
                    // there's only one channel (greyscale), hence the zero index
                    //var faces = nextFrame.DetectHaarCascade(haar)[0];
                    Image<Gray, byte> grayframe = Frame.Convert<Gray, byte>();
                    
                    var faces =
                            grayframe.DetectHaarCascade(
                                    gFacedetection, 1.4, 4,
                                    HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                    new Size(Frame.Width / 8, Frame.Height / 8)
                                    )[0];

                    
                    foreach (var face in faces)
                    {
                        CvInvoke.cvSetImageROI(grayframe, face.rect);
                        break;
                    }
                    Img = grayframe.Clone().Resize(width, height, INTER.CV_INTER_CUBIC); ;
                }
                
            }
            SR.Close();
            return Img;
        }
开发者ID:Ceasius,项目名称:University,代码行数:34,代码来源:CvUser.cs

示例3: MatchChar

        public double MatchChar(char a, char b)
        {
            Image<Bgr, Byte> pic1 = new Image<Bgr, Byte>(100, 100).Resize(matchScale, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR),
                             pic2 = new Image<Bgr, Byte>(100, 100).Resize(matchScale, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
            using (var g1 = Graphics.FromImage(pic1.Bitmap)) {
                g1.Clear(Color.Black);
                g1.DrawString(a.ToString(), new Font("Arial", 64), Brushes.White, Point.Empty);
            }
            using (var g2 = Graphics.FromImage(pic2.Bitmap)) {
                g2.Clear(Color.Black);
                g2.DrawString(b.ToString(), new Font("Comic Sans MS", 64), Brushes.White, Point.Empty);
            }

            List<Point> edge1 = findEdge(pic1.Convert<Gray, Byte>()),
                        edge2 = findEdge(pic2.Convert<Gray, Byte>());
            nsamp = Math.Min(maxsamplecount, Math.Min(edge1.Count, edge2.Count));
            edge1 = edge1.Sample(nsamp);
            edge2 = edge2.Sample(nsamp);

            Matrix t1, t2, V1, V2;
            ExtractBoundary(pic1.Convert<Gray, Byte>(), edge1, out origX, out V1, out t1);
            ExtractBoundary(pic2.Convert<Gray, Byte>(), edge2, out origY, out V2, out t2);

            return MatchIteration(origX, origY, V1, V2, t1, t2);
        }
开发者ID:pakerliu,项目名称:sharp-context,代码行数:25,代码来源:MatchImage.cs

示例4: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog Openfile = new OpenFileDialog();
            if (Openfile.ShowDialog() == DialogResult.OK)
            {
                Image<Bgr, byte> My_Image = new Image<Bgr, byte>(Openfile.FileName);
                Image<Gray, byte> gray_image = My_Image.Convert<Gray, byte>();
                Image<Gray, byte> eh_gray_image = My_Image.Convert<Gray, byte>();
                Image<Gray, byte> smooth_gray_image = My_Image.Convert<Gray, byte>();
                Image<Gray, byte> ed_gray_image = new Image<Gray, byte>(gray_image.Size);
                Image<Bgr, byte> final_image = new Image<Bgr, byte>(Openfile.FileName);
                MemStorage stor = new MemStorage();
                List<MCvBox2D> detectedLicensePlateRegionList = new List<MCvBox2D>();

                CvInvoke.cvEqualizeHist(gray_image, eh_gray_image);
                CvInvoke.cvSmooth(eh_gray_image, smooth_gray_image, Emgu.CV.CvEnum.SMOOTH_TYPE.CV_GAUSSIAN, 3, 3, 0, 0);
                //CvInvoke.cvAdaptiveThreshold(smooth_gray_image, bi_gray_image, 255, Emgu.CV.CvEnum.ADAPTIVE_THRESHOLD_TYPE.CV_ADAPTIVE_THRESH_GAUSSIAN_C, Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY, 71, 1);
                CvInvoke.cvCanny(smooth_gray_image, ed_gray_image, 100, 50, 3);
                Contour<Point> contours = ed_gray_image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE, stor);
                DetectPlate(contours, detectedLicensePlateRegionList);

                for (int i = 0; i < detectedLicensePlateRegionList.Count; i++)
                {
                    final_image.Draw(detectedLicensePlateRegionList[i], new Bgr(Color.Red), 2);
                }
                imageBox1.Image = My_Image;
                imageBox2.Image = gray_image;
                imageBox3.Image = eh_gray_image;
                imageBox4.Image = smooth_gray_image;
                imageBox5.Image = ed_gray_image;
                imageBox6.Image = final_image;
            }
        }
开发者ID:Rokeer,项目名称:Car_Plate_Recognition_Demo_1,代码行数:33,代码来源:Form1.cs

示例5: 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;
		}
开发者ID:reyrahadian,项目名称:facedetection.emgucv,代码行数:26,代码来源:image.ashx.cs

示例6: 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);
			}
		}
开发者ID:eldb2,项目名称:robotic-tic-tac-toe-lynxmotion,代码行数:27,代码来源:MainFormModel.cs

示例7: DetectSkin

 public override Image<Gray, byte> DetectSkin(Image<Bgr, byte> Img, IColor min, IColor max)
 {
     Image<Hsv, Byte> currentHsvFrame = Img.Convert<Hsv, Byte>();
     Image<Gray, byte> skin = new Image<Gray, byte>(Img.Width, Img.Height);
     skin = currentHsvFrame.InRange((Hsv)min, (Hsv)max);
     return skin;
 }
开发者ID:hzhiguang,项目名称:AbuseAnalysis,代码行数:7,代码来源:HsvSkinDetector.cs

示例8: GetColorPixelMask

        /// <summary>
        /// Compute the red pixel mask for the given image. 
        /// A red pixel is a pixel where:  20 &lt; hue &lt; 160 AND satuation &gt; 10
        /// </summary>
        /// <param name="image">The color image to find red mask from</param>
        /// <returns>The red pixel mask</returns>
        public Image<Gray, Byte> GetColorPixelMask(Image<Bgr, byte> image, int minHue, int maxHue, int minSat, int maxSat, int minValue, int maxValue)
        {
            using (Image<Hsv, Byte> hsv = image.Convert<Hsv, Byte>())
            {
                Image<Gray, Byte>[] channels = hsv.Split();
                try
                {

                    CvInvoke.cvInRangeS(channels[0], new MCvScalar(minHue), new MCvScalar(maxHue), channels[0]);
                    //CvInvoke.cvShowImage("channel 0", channels[0]);
                    //channels[1] is the mask for satuation of at least 10, this is mainly used to filter out white pixels
                    CvInvoke.cvInRangeS(channels[1], new MCvScalar(minSat), new MCvScalar(maxSat), channels[1]);

                    CvInvoke.cvInRangeS(channels[2], new MCvScalar(minValue), new MCvScalar(maxValue), channels[2]);

                    CvInvoke.cvAnd(channels[0], channels[1], channels[0], IntPtr.Zero);
                    CvInvoke.cvAnd(channels[0], channels[2], channels[0], IntPtr.Zero);
                    //CvInvoke.cvAnd(channels[0], channels[2], channels[0], IntPtr.Zero);

                }
                finally
                {
                    //CvInvoke.cvShowImage("channel 1", channels[1]);
                    //CvInvoke.cvShowImage("channel 2", channels[2]);
                    channels[1].Dispose();
                    channels[2].Dispose();
                    //channels[0].Dispose();
                }
                return channels[0];
            }
        }
开发者ID:petrind,项目名称:SRTesis2,代码行数:37,代码来源:ShapeDetector.cs

示例9: AddFaceToDB

 /// <summary>
 /// Stores a Face image and its Name in the Training Set, in MS Access Database 
 /// </summary>
 /// <param name="ImageAsBytes"></param> Face image converted to bytes 
 /// <param name="FaceName"></param>the name of face set in the textbox
 private void AddFaceToDB(Image InputFace, string FaceName)
 {
     Image<Bgr, byte> grayframe = new Image<Bgr, byte>(new Bitmap(InputFace));
     Image<Gray, byte> faceGrayPic = grayframe.Convert<Gray, Byte>().Resize(64, 64, Emgu.CV.CvEnum.Inter.Cubic);
     faceGrayPic.Save("trainingset/"+txtBoxFaceName.Text+".bmp");
     MessageBox.Show("nailigtas");
 }
开发者ID:ButialRalph,项目名称:SeeSharp,代码行数:12,代码来源:TrainingSetEditor.cs

示例10: colorMask

        private Image<Gray, Byte> colorMask(Image<Bgr, Byte> bgrImage)
        {
            Image<Hsv, Byte> hsvImg = bgrImage.Convert<Hsv, Byte>();
              Image<Gray, Byte>[] channels = hsvImg.Split();
              Image<Gray, Byte> imghue = channels[0];            //hsv, so channels[0] is hue.
              Image<Gray, Byte> imgval = channels[2];            //hsv, so channels[2] is value.
              Image<Gray, Byte> imgsat = channels[1];            //hsv, so channels[1] is

              minHue = hueMinTB.Value;
              maxHue = hueMaxTB.Value;
              minSat = satMinTB.Value;
              maxSat = satMaxTB.Value;
              minVal = valMinTB.Value;
              maxVal = valMaxTB.Value;

              //filter out all but "the color you want"...seems to be 0 to 128 ?
              Image<Gray, byte> huefilter = imghue.InRange(new Gray(minHue ), new Gray(maxHue ));
              Image<Gray, byte> satfilter = imgsat.InRange(new Gray(minSat ), new Gray(maxSat ));

              //use the value channel to filter out all but brighter colors
              //Image<Gray, byte> valfilter = imgval.InRange(new Gray(Color.Orange .GetBrightness() - 5), new Gray(Color.Orange .GetBrightness() + 5));
              Image<Gray, byte> valfilter = imgval.InRange(new Gray(minVal ), new Gray(maxVal));

              //now and the two to get the parts of the imaged that are colored and above some brightness.
              Image<Gray, byte> detimg = huefilter.And(valfilter).And(satfilter);
              return detimg;
        }
开发者ID:srivera4,项目名称:imageWithSpeech,代码行数:27,代码来源:Form1.cs

示例11: 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);
            }
        }
开发者ID:AndreuChel,项目名称:facedetect,代码行数:60,代码来源:default.aspx.cs

示例12: GetRedPixelMask

        /// <summary>
        /// Compute the red pixel mask for the given image. 
        /// A red pixel is a pixel where:  20 &lt; hue &lt; 160 AND satuation &gt; 10
        /// </summary>
        /// <param name="image">The color image to find red mask from</param>
        /// <returns>The red pixel mask</returns>
        public static Image<Gray, Byte> GetRedPixelMask(Image<Bgr, byte> image)
        {
            using (Image<Hsv, Byte> hsv = image.Convert<Hsv, Byte>())
            {
                Image<Gray, Byte>[] channels = hsv.Split();

                try
                {
                    //channels[0] is the mask for hue less than 20 or larger than 160
                    CvInvoke.cvInRangeS(channels[0], new MCvScalar(MaskHueLow), new MCvScalar(MaskHueHigh), channels[0]);
                    channels[0]._Not();

                    //channels[1] is the mask for satuation of at least 10, this is mainly used to filter out white pixels
                    channels[1]._ThresholdBinary(new Gray(10), new Gray(255.0));

                    CvInvoke.cvAnd(channels[0], channels[1], channels[0], IntPtr.Zero);
                }
                finally
                {
                    channels[1].Dispose();
                    channels[2].Dispose();
                }
                return channels[0];
            }
        }
开发者ID:quadrowin,项目名称:afkgamer,代码行数:31,代码来源:StopSignDetector.cs

示例13: Run

        public void Run()
        {
            base.Output = new cImage(Input.Width, Input.Height, Input.Depth, base.ListChannelsToBeProcessed.Count);
            for (int IdxChannel = 0; IdxChannel < base.ListChannelsToBeProcessed.Count; IdxChannel++)
            {
                int CurrentChannel = base.ListChannelsToBeProcessed[IdxChannel];

                Image<Gray, float> inputImage = new Image<Gray, float>(Input.Width, Input.Height);

                for (int j = 0; j < Input.Height; j++)
                    for (int i = 0; i < Input.Width; i++)
                        inputImage.Data[j, i, 0] = Input.SingleChannelImage[CurrentChannel].Data[i + j * Input.Width];

                Image<Gray, float> ProcessedImage = new Image<Gray, float>(inputImage.Width, inputImage.Height);

                Emgu.CV.Image<Gray, byte> gray = inputImage.Convert<Gray, byte>();//convert to grayscale
                IntPtr dsti = Emgu.CV.CvInvoke.cvCreateImage(Emgu.CV.CvInvoke.cvGetSize(gray), Emgu.CV.CvEnum.IplDepth.IplDepth32F, 1);
                //TODO: Has to be checked!!!!

                Emgu.CV.CvInvoke.DistanceTransform(gray, ProcessedImage,null, DistanceType, MaskSize, DistLabelType.CComp);

                this.Output.SingleChannelImage[IdxChannel].SetNewDataFromOpenCV(ProcessedImage);
            }
            return;
        }
开发者ID:cyrenaique,项目名称:HCSA,代码行数:25,代码来源:cImageDistanceMap.cs

示例14: BoardButton_Click

        private void BoardButton_Click(object sender, RoutedEventArgs e)
        {
            string[] args = Environment.GetCommandLineArgs();
            Image<Hsv, byte> img = new Image<Hsv, byte>(args[1]);

            Image<Gray, byte> blue = ImageTools.FilterColor(img, new Hsv(90, 90, 50), new Hsv(120, 255, 255));
            Image<Gray, byte> green = ImageTools.FilterColor(img, new Hsv(35, 70, 35), new Hsv(90, 255, 255));
            Image<Gray, byte> yellow = ImageTools.FilterColor(img, new Hsv(10, 70, 127), new Hsv(35, 255, 255));
            Image<Gray, byte> red = ImageTools.FilterColor(
                img,
                new KeyValuePair<Hsv, Hsv>[]{
                    new KeyValuePair<Hsv,Hsv>(new Hsv(0, 85, 80), new Hsv(12, 255, 255)),
                    new KeyValuePair<Hsv,Hsv>(new Hsv(150,85,80), new Hsv(179,255,255))
                }
            );

            DetectionData ddb = ImageTools.DetectSquares(blue);
            DetectionData ddr = ImageTools.DetectSquares(red);
            DetectionData ddg = ImageTools.DetectSquares(green);
            DetectionData ddy = ImageTools.DetectSquares(yellow);
            ddb.RemoveNoises();
            ddr.RemoveNoises();
            ddg.RemoveNoises();
            ddy.RemoveNoises();
            ddb.AddColor(ddr);
            ddb.AddColor(ddg);
            ddb.AddColor(ddy);

            var board = ddb.CreateBoard();
            var di = ddb.DrawDetection().Bitmap;
            MessageBox.Show("Detected board: " + board.Height + "x" + board.Width);

            ImageTools.ShowInNamedWindow(img.Convert<Bgr, byte>(), "Original");
        }
开发者ID:DormantDreams,项目名称:video-game-level-scanner,代码行数:34,代码来源:MainWindow.xaml.cs

示例15: LineDetectionFromFileTesting

        public LineDetectionFromFileTesting()
        {
            viewer = new ImageViewer(); //create an image viewer

            //Convert the image to grayscale and filter out the noise
            // gray = new Image<Gray, Byte>("C:/RoboSub/RoboImagesTest2/92c.png");
            fileImage = new Image<Bgr, Byte>(fileName);
            fileImage = fileImage.Resize(300, 200, Emgu.CV.CvEnum.INTER.CV_INTER_AREA, true);
            img = fileImage.Clone();
            gray = img.Convert<Gray, Byte>();
            // img = new Image<Bgr, Byte>("C:/RoboSub/RoboImagesTest2/92c.png");

            viewer.Size = new Size(fileImage.Width * 3, fileImage.Height * 3);

            Thread input = new Thread(getKeyboardInput);
            input.Start();
            Thread test = new Thread(testShapeDetection);
            test.Start();
            Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
            {
                //testShapeDetection();
            });
            viewer.ShowDialog();
            test.Abort();
            input.Abort();
        }
开发者ID:MorgThom,项目名称:sos-sub,代码行数:26,代码来源:LineDetectionFromFileTesting.cs


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