实例目的:提取最上面黄色的线
在HDevelop中
dev_close_window ()
read_image (Image, 'D:/bb/tu/8.png')
get_image_size (Image, Width, Height)
decompose3 (Image, Red, Green, Blue)
*将RGB三通道数据转化为HSV色彩空间的三通道图像数据
*HSV:看
trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv')
对HSV图像中的饱和度通道进行阈值操作
threshold (Saturation, HighSaturation, 200, 255)
*获取上述阈值操作后区域中的色调通道图像数据
reduce_domain (Hue, HighSaturation, HueHighSaturation)
*对上述色调通道图像数据进行阈值处理
threshold (HueHighSaturation, Yellow, 20, 30)
*寻找连通域
connection (Yellow, ConnectedRegions)
*保留ConnectedRegions里的最大的区域
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 0)
*对SelectedRegions进行闭运算操作
closing_circle (SelectedRegions, Yellow, 3.5)
*将Yellow区域里的图像剪切出来
reduce_domain (Image, Yellow, ImageReduced)
dev_open_window(10,10,Width, Height,'black',WindowHandle)
dev_display(ImageReduced)
在Qt Creator中
HObject ho_Image, ho_Red, ho_Green, ho_Blue;
HObject ho_Hue, ho_Saturation, ho_Intensity, ho_HighSaturation;
HObject ho_HueHighSaturation, ho_Yellow, ho_ConnectedRegions;
HObject ho_SelectedRegions, ho_ImageReduced;
HTuple hv_Width, hv_Height, hv_WindowHandle;
ReadImage(&ho_Image, "D:/bb/tu/8.png");
GetImageSize(ho_Image, &hv_Width, &hv_Height);
Decompose3(ho_Image, &ho_Red, &ho_Green, &ho_Blue);
//将RGB三通道数据转化为HSV色彩空间的三通道图像数据
//HSV:看
TransFromRgb(ho_Red, ho_Green, ho_Blue, &ho_Hue, &ho_Saturation, &ho_Intensity,
"hsv");
//对HSV图像中的饱和度通道进行阈值操作
Threshold(ho_Saturation, &ho_HighSaturation, 200, 255);
//获取上述阈值操作后区域中的色调通道图像数据
ReduceDomain(ho_Hue, ho_HighSaturation, &ho_HueHighSaturation);
//对上述色调通道图像数据进行阈值处理
Threshold(ho_HueHighSaturation, &ho_Yellow, 20, 30);
//寻找连通域
Connection(ho_Yellow, &ho_ConnectedRegions);
//保留ConnectedRegions里的最大的区域
SelectShapeStd(ho_ConnectedRegions, &ho_SelectedRegions, "max_area", 0);
//对SelectedRegions进行闭运算操作
ClosingCircle(ho_SelectedRegions, &ho_Yellow, 3.5);
//将Yellow区域里的图像剪切出来
ReduceDomain(ho_Image, ho_Yellow, &ho_ImageReduced);
SetWindowAttr("background_color","black");
OpenWindow(10,10,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle);
HDevWindowStack::Push(hv_WindowHandle);
if (HDevWindowStack::IsOpen())
DispObj(ho_ImageReduced, HDevWindowStack::GetActive());