C++中显示Halcon窗口(2D&3D)

C++打开窗口显示Halcon图片

void ImageDisplay(Hobject Image, Hobject Regions)
{
#if defined(_DEBUGTEST)
	HTuple WindowHandle;
	set_window_attr("background_color", "black");
	open_window(0, 0, 1200, 900, 0, "", "visible", &WindowHandle);
	HDevWindowStack::Push(WindowHandle);
	HDevWindowStack::SetActive(WindowHandle);
	if (HDevWindowStack::IsOpen())
	{
		set_color(HDevWindowStack::GetActive(), "red");
		set_draw(HDevWindowStack::GetActive(), "margin");
		disp_obj(Image, HDevWindowStack::GetActive());
		disp_obj(Regions, HDevWindowStack::GetActive());
	}
	wait_seconds(5.0);//Halcon18用
	//getchar();(Halcon10等待专用)
	close_window(WindowHandle);
#endif
}

c++&Halcon 的显示3D方法后面更新
Halcon导出的visualization_object_model_3d算子中,全部照抄,会一闪而过,尽管增加等待,移动点云也会很卡;
解决办法是:将disp_text_button中的DispText函数注释掉,因为鼠标在屏幕上触动一下,就会调用DispText,然而这会拖慢显示效率;
修改如下:
1.注释DispText算子
注释掉DispText算子
2.在visualize_object_model_3d中增加延时
C++中显示Halcon窗口(2D&3D)_第1张图片
详细见showCloud.h 链接:https://download.csdn.net/download/qq_34176467/76767944
示例如下:


#include 
#include 
#include "showCloud.h"
using namespace std;
using namespace HalconCpp;


void genCloud(HTuple* objectModel3D)
{
	HObject image,region;
	HTuple arr_x, arr_y, arr_z;
	ReadImage(&image, "C:\\Users\\Public\\Documents\\MVTec\\HALCON-18.11-Progress\\examples\\images\\printer_chip\\printer_chip_01.png");
	Threshold(image, &region, 0, 255);
	GetRegionPoints(region, &arr_x, &arr_y);
	GetGrayval(image, arr_x, arr_y, &arr_z);
	HalconCpp::GenObjectModel3dFromPoints(arr_x, arr_y, arr_z, objectModel3D);
	return;
}

void showCloudH(HTuple objectModel3D)
{
	HTuple WindowHandle;
	HalconCpp::SetWindowAttr("background_color", "black");
	HalconCpp::OpenWindow(0, 0, 524, 524, 0, "", "visible", &WindowHandle);
	HDevWindowStack::Push(WindowHandle);
	HDevWindowStack::SetActive(WindowHandle);
	HTuple Pose;
	if (HDevWindowStack::IsOpen())
	{
		visualize_object_model_3d(WindowHandle, objectModel3D,HTuple(),HTuple(),HTuple(), HTuple(), HTuple(), HTuple(), HTuple(), &Pose);
	}
	CloseWindow(WindowHandle);
}

int main()
{
	HTuple objectModel3D;
	genCloud(&objectModel3D);
	showCloudH(objectModel3D);
	return 0;
}

Halcon联合调试的时候,注意try catch的使用

//如:
try
	{
		HalconCpp::ReadImage(&textImage, "ooo.jpg");
 
	}
	catch (HalconCpp::HException& exception)
	{
		std::cout << (const char*)(exception.ErrorMessage()) << std::endl;
		return;
	}
C++ &PCL显示点云

```cpp
void showCloudPCL(pcl::PointCloud::Ptr cloud)
{
	pcl::visualization::PointCloudColorHandlerCustom color(255, 0, 0);
	pcl::visualization::PointCloudColorHandlerGenericField fcolor(cloud,"z");
	boost::shared_ptr< pcl::visualization::PCLVisualizer > viewer(new 	pcl::visualization::PCLVisualizer("3D Viewer"));
	viewer->setBackgroundColor(0, 0, 0);
	viewer->addPointCloud(cloud, fcolor, "sample cloud1");
	while (!viewer->wasStopped())
	{
		viewer->spinOnce(100);
		boost::this_thread::sleep(boost::posix_time::microseconds(1000));
	}
	return;
}

你可能感兴趣的:(c++,开发语言,后端)