halcon基本示例之灰度直方图

void test()
{
    HImage image("2.jpg");
    HImage gray = image.Rgb1ToGray();//转化为灰度图
    Hlong width, height;
    image.GetImageSize(&width, &height);
    HRegion region;
    region.GenRectangle1(0, 0, height-1, width-1);//创建一个矩形
    HTuple AbsoluteHisto, RelativeHisto;
    AbsoluteHisto = region.GrayHisto(image, &RelativeHisto);//获得区域内的灰度值分布AbsoluteHisto表示灰度值对应像素个数,RelativeHisto代表归一化后值 
    HRegion histo;
    histo.GenRegionHisto(AbsoluteHisto, 0, 0, 1);//根据AbsoluteHisto或者RelativeHisto生成灰度直方图区域
    HWindow w(0, 0, 500, 500);
    HWindow w0(0, 0, width, height);
    w.SetColor("red");
    w.DispRegion(histo);
    w0.DispImage(gray);
    w.Click();
}
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页