1.halcon 图片中添加区域HRegion
彩色图片C++ 实现
HObject ho_ImageResult1;
GenEmptyObj(&ho_ImageResult1);
PaintRegion(ho_Regions, ho_Image, &ho_ImageResult1, ((HTuple(255).Append(255)).Append(255)), "fill");
WriteImage(ho_ImageResult1, "bmp", 0, ".\\ho_ImageResult1");
2.C++ 函数封装实现
头文件
void save_rgb_Region(HObject ho_region, HObject ho_Image, HTuple hv_filePath);
void save_gray_region(HObject ho_region, HObject ho_Image, HTuple hv_filePath);
C++文件
void save_rgb_Region(HObject ho_region, HObject ho_Image, HTuple hv_filePath)
{
HObject ho_ImageResult;
GenEmptyObj(&ho_ImageResult);
PaintRegion(ho_region, ho_Image, &ho_ImageResult, ((HTuple(255).Append(255)).Append(255)), "fill");
WriteImage(ho_ImageResult, "bmp", 0, hv_filePath);
}
void save_gray_region(HObject ho_region, HObject ho_Image, HTuple hv_filePath)
{
HObject ho_ImageR, ho_ImageG, ho_ImageB, ho_imgRGB;
PaintRegion(ho_region, ho_Image, &ho_ImageR, 255, "fill");
PaintRegion(ho_region, ho_Image, &ho_ImageG, 0, "fill");
PaintRegion(ho_region, ho_Image, &ho_ImageB, 0, "fill");
Compose3(ho_ImageR, ho_ImageG, ho_ImageB, &ho_imgRGB);
WriteImage(ho_imgRGB, "bmp", 0, hv_filePath);
}
halcon C++ 循环读取HTuple
HTuple hv_Index1, hv_pathFile;
HTuple end_val86 = pathModels.TupleLength();
HTuple step_val86 = 1;
for (hv_Index1 = 1; hv_Index1.Continue(end_val86, step_val86); hv_Index1 += step_val86)
{
hv_pathFile = HTuple(pathModels[hv_Index1 - 1]);
cout << hv_pathFile.ToString().Text();
}