【问题标题】:How to copy segment from the image?如何从图像中复制片段?
【发布时间】:2013-11-24 18:22:27
【问题描述】:

我有 Emgu 图片:

Image<Bgr,byte> image = new Image<Bgr,byte>("image.jpg"); 

文件(image.jpg)如下所示:

我要复制到名为的新图像中的红黄色三角形内的所有像素:

Image<Bgr,byte> copiedSegment;

如果我有坐标三角形轮廓的所有坐标,知道如何实现它。

提前谢谢你。

【问题讨论】:

    标签: c# opencv image-processing emgucv


    【解决方案1】:

    在 opencv c++ api 中,您可以使用矩阵复制功能和由三角形组件组成的掩码。

    Mat image = imread("image.jpg",CV_LOAD_IMAGE_COLOR);
    vector<Point> triangleRoi;
    Mat mask;
    
    //draw your trianlge on the mask
    cv::fillConvexPoly(mask, triangleRoi, 255);
    
    Mat copiedSegment;
    image.copyTo(copiedSegment,mask);
    

    你应该可以基于此在emgu中写一些类似的代码。

    【讨论】:

    • 元素,感谢您的回答。任何想法如何制作不在多边形内的透明像素?
    • 为了利用透明度,我建议您查看 OpenCV 文档中的第 4 个通道。将您的图片初始化为CV_8UC4,并为第四个通道创建一个带有零的cv::Mat,然后将提取的三通道图像与这个“空白”通道合并。
    • scap,EMGU 中合适的 Mat 类型是什么?有什么想法吗?
    【解决方案2】:
    // no we apply filter to get rid of Equalization Noise.
    ImageBilateral = new Image<Gray, Byte>(grayImg.Size);
    CvInvoke.BilateralFilter(grayImg, ImageBilateral, 0, 20.0, 2.0);
    //ImageBilateral.Save(String.Format("C:\\Temp\\BilateralFilter{0}.jpg", counter));
    
    retImage = AlignFace(ImageBilateral);
    
    Point faceCenter = new Point(ImageBilateral.Width / 2, (int)Math.Round(ImageBilateral.Height * FACE_ELLIPSE_CY));
    Size size = new Size((int)Math.Round(ImageBilateral.Width * FACE_ELLIPSE_W), (int)Math.Round(ImageBilateral.Width * FACE_ELLIPSE_H));
    
    // Filter out the corners of the face, since we mainly just care about the middle parts.
    // Draw a filled ellipse in the middle of the face-sized image.
    Image<Gray, Byte> mask = new Image<Gray, Byte>(ImageBilateral.Size);
    
    // draw Ellipse on Mask
    CvInvoke.Ellipse(mask, faceCenter, size, 0, 0, 360, new MCvScalar(255, 255, 255), -1, Emgu.CV.CvEnum.LineType.AntiAlias, 0);
    mask.Save(String.Format("C:\\Temp\\mask{0}.bmp", counter));
    
    Image<Gray, Byte> temp1 = ImageBilateral.Copy(mask);
    ImageBilateral.Save(String.Format("C:\\Temp\\ImageBilateral.CopyTo(mask){0}.bmp", counter));
    temp1.Save(String.Format("C:\\Temp\\temp1{0}.bmp", counter));
    

    【讨论】:

      猜你喜欢
      • 2021-12-13
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多