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


C# IplImage.Copy方法代码示例

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


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

示例1: Inpaint

        public Inpaint()
        {
            // cvInpaint
            // 画像の不要な文字列部分に対するマスク画像を指定して文字列を除去する

            Console.WriteLine(
                "Hot keys: \n" +
                "\tESC - quit the program\n" +
                "\tr - restore the original image\n" +
                "\ti or ENTER - run inpainting algorithm\n" +
                "\t\t(before running it, paint something on the image)\n" +
                "\ts - save the original image, mask image, original+mask image and inpainted image to desktop."
            );

            // 原画像の読み込み
            using (IplImage img0 = new IplImage(Const.ImageFruits, LoadMode.AnyDepth | LoadMode.AnyColor))
            {
                // お絵かき用の画像を確保(マスク)
                using (IplImage img = img0.Clone())
                using (IplImage inpaintMask = new IplImage(img0.Size, BitDepth.U8, 1))
                // Inpaintの出力先画像を確保
                using (IplImage inpainted = img0.Clone())
                {
                    inpainted.Zero();
                    inpaintMask.Zero();

                    using (CvWindow wImage = new CvWindow("image", WindowMode.AutoSize, img))
                    {

                        // マウスイベントの処理
                        CvPoint prevPt = new CvPoint(-1, -1);
                        wImage.OnMouseCallback += delegate(MouseEvent ev, int x, int y, MouseEvent flags)
                        {
                            if (ev == MouseEvent.LButtonUp || (flags & MouseEvent.FlagLButton) == 0)
                            {
                                prevPt = new CvPoint(-1, -1);
                            }
                            else if (ev == MouseEvent.LButtonDown)
                            {
                                prevPt = new CvPoint(x, y);
                            }
                            else if (ev == MouseEvent.MouseMove && (flags & MouseEvent.FlagLButton) != 0)
                            {
                                CvPoint pt = new CvPoint(x, y);
                                if (prevPt.X < 0)
                                {
                                    prevPt = pt;
                                }
                                inpaintMask.Line(prevPt, pt, CvColor.White, 5, LineType.AntiAlias, 0);
                                img.Line(prevPt, pt, CvColor.White, 5, LineType.AntiAlias, 0);
                                prevPt = pt;
                                wImage.ShowImage(img);
                            }
                        };

                        for (; ; )
                        {
                            switch ((char)CvWindow.WaitKey(0))
                            {
                                case (char)27:    // ESCキーで終了
                                    CvWindow.DestroyAllWindows();
                                    return;
                                case 'r':   // 原画像を復元
                                    inpaintMask.Zero();
                                    img0.Copy(img);
                                    wImage.ShowImage(img);
                                    break;
                                case 'i':   // Inpaintの実行
                                case '\r':
                                    CvWindow wInpaint = new CvWindow("inpainted image", WindowMode.AutoSize);
                                    img.Inpaint(inpaintMask, inpainted, 3, InpaintMethod.Telea);
                                    wInpaint.ShowImage(inpainted);
                                    break;
                                case 's': // 画像の保存
                                    string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                                    img0.SaveImage(Path.Combine(desktop, "original.png"));
                                    inpaintMask.SaveImage(Path.Combine(desktop, "mask.png"));
                                    img.SaveImage(Path.Combine(desktop, "original+mask.png"));
                                    inpainted.SaveImage(Path.Combine(desktop, "inpainted.png"));
                                    break;
                            }
                        }

                    }

                }
            }

        }
开发者ID:healtech,项目名称:opencvsharp,代码行数:89,代码来源:Inpaint.cs

示例2: AllMatching

        /// <summary>
        /// 指定した分割数でそろばんを全て読み取る
        /// </summary>
        /// <param name="source">そろばんの画像</param>
        /// <param name="threshold">しきい値</param>
        /// <param name="process_img">処理画像</param>
        /// <returns>読み取った数値(-1はエラー)</returns>
        public int[] AllMatching(IplImage source, double threshold, out IplImage process_img)
        {
            // グレースケール画像
            IplImage cap_gray = new IplImage(PROCESS_SIZE, BitDepth.U8, 1);

            // キャプチャとリサイズ,グレースケール変換
            using (IplImage tmp = new IplImage(
                PROCESS_SIZE, source.Depth, source.NChannels))
            {
                source.Resize(tmp);
                tmp.CvtColor(cap_gray, ColorConversion.BgrToGray);
            }

            int[] results = new int[DIVIDE_NUM];
            int width = cap_gray.Width / (DIVIDE_NUM + 1);
            int margin = (int)(width * DIVIDE_MARGIN);

            // 領域ごとに処理
            Parallel.For(0, DIVIDE_NUM, i =>
            {
                IplImage tmp = new IplImage(PROCESS_SIZE, BitDepth.U8, 1);
                cap_gray.Copy(tmp);

                int x = (i + 1) * width - width / 2;
                // 領域を指定
                CvRect rect = new CvRect(x - margin, 0, width + margin * 2, PROCESS_SIZE.Height);
                tmp.SetROI(rect);

                // 0-9の画像とMatchTemplateし一番高い値を得る
                results[i] = bestMatchNum(tmp, this.templates[i], threshold);

                // 領域の指定を解除
                tmp.ResetROI();
            });

            // 分割線の描画
            for (int i = 1; i < DIVIDE_NUM + 2; i++)
            {
                int x = i * width - width / 2;
                cap_gray.Line(x, 0, x, PROCESS_SIZE.Height, CvColor.White);
            }

            // 読み取り数値を表示
            CvFont font = new CvFont(FontFace.HersheyDuplex, 1.0, 1.0);
            for (int i = 0; i < DIVIDE_NUM; i++)
            {
                if (results[i] != -1)
                {
                    int x = i * width + width / 2;
                    cap_gray.PutText(results[i].ToString(), new CvPoint(x, 30),
                        font, CvColor.White);
                }
            }

            // 分割線, 読み取り数値画像を返す
            process_img = cap_gray;

            return results;
        }
开发者ID:nnct-jo-ken,项目名称:SorobanReader,代码行数:66,代码来源:SorobanReader.cs

示例3: Update

	// Update is called once per frame
	void Update () {
	
		if (!close)
		{
			IplImage src = cap.QueryFrame();

            IplImage next = new IplImage(cols, rows, BitDepth.U8, 1);

            IplImage rez = new IplImage(cols, rows, BitDepth.U8, 3);
            src.Copy(rez);

			CvMat velx = Cv.CreateMat(rows, cols, MatrixType.F32C1);
			CvMat vely = Cv.CreateMat(rows, cols, MatrixType.F32C1);

			src.CvtColor(next, ColorConversion.BgrToGray);
			//uu = new CvMat(src.GetRow, src.GetCol, BitDepth.U8,
			//src.CvtColor(uu,ColorConversion.BgrToGray);
			//Cv.AbsDiff(prvs,next, rez);
			//Cv.CalcOpticalFlowFarneback(prvs,next,rez,0.5, 3, 15, 3, 5, 1.2, 0);
			//Cv.Canny(next, dstCanny, 50, 50, ApertureSize.Size3);
			//Cv.Erode(
			//Cv.Threshold(prvs,prvs,100,255,ThresholdType.Mask);
			//Cv.Threshold(next,next,100,255,ThresholdType.Mask);

		//	next.InRangeS(CvScalar(160,120,120), CvScalar(179,255,255),next);
        //    Cv.Erode(prvs, prvs, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));
        //    Cv.Dilate(prvs, prvs, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));
         //   Cv.Erode(next, next, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));
        //    Cv.Dilate(next, next, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));

       //     Cv.Dilate(prvs, prvs, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));
       //     Cv.Erode(prvs, prvs, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));
	
        //    Cv.Dilate(next, next, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));
        //    Cv.Erode(next, next, Cv.CreateStructuringElementEx(15, 15, 7, 7, ElementShape.Ellipse));


            Cv.Threshold(next, next, 120, 255, ThresholdType.Truncate);
            Cv.Threshold(prvs, prvs, 120, 255, ThresholdType.Truncate);
            
           
			Cv.CalcOpticalFlowLK(prvs,next,Cv.Size(15,15),velx,vely);
	    	CalcPoint(velx,vely,rez);
		//	DrawOpticalFlow(velx,vely,rez);
            FromIplImageToTexture(rez, planeRight);
           // FromIplImageToTexture(src, planeLeft);

			if (Input.GetKey (KeyCode.Space)) {
				src.SaveImage("Assets/1.jpg");
				Debug.Log("Save");
			
			}


			w.Image = rez;
			next.Copy(prvs);

			
		
		}
		//Debug.Log (move.x);
		if (Input.GetKey (KeyCode.Escape)) {
			close = true;
			w.Close();
		}

	}
开发者ID:MaksimSychugov,项目名称:SpaceshipGesture,代码行数:68,代码来源:UnityCvTest.cs

示例4: Update

	// Update is called once per frame
	void Update () {

        FromTextureToIplImage(src);
        IplImage next = new IplImage(imWidth, imHeight, BitDepth.U8, 1);
        IplImage prvs = new IplImage(imWidth, imHeight, BitDepth.U8, 1);
        CvMat velx = new CvMat(imWidth, imHeight, MatrixType.F32C2);
        CvMat vely = new CvMat(imWidth, imHeight, MatrixType.F32C2);
     
        if (fl)
        {
           
            Cv.CvtColor(src, next, ColorConversion.BgrToGray);
            Cv.Threshold(next, next, 90, 255, ThresholdType.Truncate);
            Cv.Threshold(prvs, prvs, 90, 255, ThresholdType.Truncate);
           //s Cv.AbsDiff
          //  Cv.CalcOpticalFlowFarneback(prvs, next, velx, 0.5, 3, 15, 3, 5, 1.2, 0);
        //    Cv.CalcOpticalFlowLK(prvs, next, Cv.Size(15, 15), velx, vely);
         //   CalcPoint(velx, vely, rez);

            w.Image = rez;
            next.Copy(prvs);
        }
        if (!fl) 
        {
           
            Cv.CvtColor(src, prvs, ColorConversion.BgrToGray);
       //     w.Image = prvs;
            fl = true;
        }


	    
	}
开发者ID:MaksimSychugov,项目名称:SpaceshipGesture,代码行数:34,代码来源:WebCamera.cs


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