当前位置:网站首页>Halcon 绘制区域 到图片中

Halcon 绘制区域 到图片中

2022-06-24 13:00:00 廷益--飞鸟

将区域绘制到图片中(灰度图)

区域颜色使用的是 白色

public static HImage WriteRegion(HImage baseImg, HRegion wRegion)
{
    
    int nWidth, nHeight;
    baseImg.GetImageSize(out nWidth, out nHeight);
    HImage zeroImage = new HImage();
    zeroImage.GenImageConst("byte", nWidth, nHeight);
    zeroImage = zeroImage.PaintRegion(wRegion, (HTuple)255, "fill");
    
    return zeroImage;
}

将区域绘制到图片中 (彩色图片)

区域的颜色可以使用 RGB分量设置。

public static HImage GetRegionRGB(HImage baseImg, HRegion wRegion, int iR, int iG, int iB)
{
    
    HImage imgResult = baseImg.CopyImage();

    HImage imgR = new HImage();
    HImage imgB = new HImage();
    HImage imgG = new HImage();

    HRegion wBig = wRegion.DilationCircle(3.5);
    HRegion wInside = wRegion.DilationCircle(1.5);
    HRegion outRegion = wBig.Difference(wInside);

    imgR = imgResult.Decompose3(out imgG, out imgB);
    imgR = imgR.PaintRegion(outRegion, (HTuple)iR, "fill");
    imgG = imgG.PaintRegion(outRegion, (HTuple)iG, "fill");
    imgB = imgB.PaintRegion(outRegion, (HTuple)iB, "fill");

    imgResult = imgR.Compose3(imgG, imgB);

    return imgResult;
}
原网站

版权声明
本文为[廷益--飞鸟]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45875105/article/details/125415077