halcon-gray_histo计算直方图
作者:互联网
ma.jpg
在HDevelop中
dev_update_off() read_image (Image, 'D:/bb/tu/ma.jpg') rgb1_to_gray(Image,Image1) *将RGB图像转换为灰度图像 get_image_size (Image1, Width, Height) dev_open_window(10,10,Width, Height,'black',WindowHandle) get_domain (Image1, Domain) gray_histo (Domain, Image1, AbsoluteHisto, RelativeHisto) *计算直方图:指定区域 *为区域内的图像计算灰度值的绝对和相对直方图 *参数1:要计算直方图的区域 *参数2:要计算其灰度值分布的图像 *参数3:是指图像内0-255灰度值出现的次数-->直方图 *参数4:将上面的出现次数转化为频率,总合为1 histo_to_thresh (AbsoluteHisto, 2, MinThresh, MaxThresh) *根据直方图确定阈值 *参数1:灰度直方图 *参数2:用于直方图的高斯平滑;建议值:0.5, 1.0, 2.0, 3.0, 4.0, 5.0 *参数3:最低阈值 [0, 56, 66, 128, 159, 190, 199, 213, 225] *参数4:最大阈值 [55, 65, 127, 158, 189, 198, 212, 224, 255] threshold (Image1, Region, MinThresh, MaxThresh)
*参数3和参数4是一一对应的阈值数组,根据阈值同时分割出多个区域 dev_display(Region)
在QtCreator中
HObject ho_Image, ho_Image1, ho_Domain, ho_Region; HTuple hv_Width, hv_Height, hv_WindowHandle; HTuple hv_AbsoluteHisto, hv_RelativeHisto, hv_MinThresh; HTuple hv_MaxThresh;
ReadImage(&ho_Image, "D:/bb/tu/ma.jpg"); Rgb1ToGray(ho_Image, &ho_Image1); //将RGB图像转换为灰度图像 GetImageSize(ho_Image1, &hv_Width, &hv_Height); SetWindowAttr("background_color","black"); OpenWindow(10,10,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle); HDevWindowStack::Push(hv_WindowHandle); GetDomain(ho_Image1, &ho_Domain); GrayHisto(ho_Domain, ho_Image1, &hv_AbsoluteHisto, &hv_RelativeHisto); //计算直方图:指定区域 //为区域内的图像计算灰度值的绝对和相对直方图 //参数1:要计算直方图的区域 //参数2:要计算其灰度值分布的图像 //参数3:是指图像内0-255灰度值出现的次数-->直方图 //参数4:将上面的出现次数转化为频率,总合为1 HistoToThresh(hv_AbsoluteHisto, 2, &hv_MinThresh, &hv_MaxThresh); //根据直方图确定阈值 //参数1:灰度直方图 //参数2:用于直方图的高斯平滑;建议值:0.5, 1.0, 2.0, 3.0, 4.0, 5.0 //参数3:最低阈值 [0, 56, 66, 128, 159, 190, 199, 213, 225] //参数4:最大阈值 [55, 65, 127, 158, 189, 198, 212, 224, 255] Threshold(ho_Image1, &ho_Region, hv_MinThresh, hv_MaxThresh); if (HDevWindowStack::IsOpen()) DispObj(ho_Region, HDevWindowStack::GetActive());
标签:gray,hv,直方图,参数,ho,histo,灰度,Image1 来源: https://www.cnblogs.com/liming19680104/p/15970345.html