知微传感Dkam系列3D相机SDK例程篇:连接相机采集并保存数据

序言

写在前面

  • 编写此系列文章主要目的有:
    • 1、便利他人应用相机,本系列文章包含公司所出售相机的SDK的使用例程及详细注释;
    • 2、促进行业发展及交流。

DKAM系列3D相机SDK例程及注释

相机连接、数据采集及保存

  • 本例程基于WIN11+VisualStudio2022+DkamSDK_1.6.72,采用C++语言
  • SDK的配置方法,请参考官方提供的SDK说明书
#include 
#include
#include"dkam_discovery.h"
#include"dkam_gige_camera.h"
#include"dkam_gige_stream.h"


int main()
{
    std::cout << "Hello Zhisensor!\n";

	std::vector discovery_info;
	Discovery discovery;
	GigeCamera camera;
	GigeStream* pointgigestream = NULL;

	std::vector().swap(discovery_info);

	//****************************************查找局域网内相机********************************************
	int k = -1;
	//查找相机
	int camer_num = discovery.DiscoverCamera(&discovery_info);
	std::cout << "局域网内相机数量为:" << camer_num << std::endl;
	//对局域网内的相机进行排序0:IP 1:相机序列号
	int camer_sort = discovery.CameraSort(&discovery_info, 1);
	std::cout << "camer_sort=" << camer_sort << std::endl;
	//显示局域网内相机的IP	
	for (int i = 0; i < camer_num; i++) {
		std::cout << "IP为:" << discovery.ConvertIpIntToString(discovery_info[i].camera_ip) << std::endl;
		if (strcmp((discovery.ConvertIpIntToString(discovery_info[i].camera_ip)), "169.254.30.44") == 0) {
			k = i;
		}
	}

	//****************************************连接局域网内指定的相机******************************************
	//连接相机,相机的IP与上面的IP相同,若想获取相机IP可以先通过知微传感提供的DkamViewer软件查询
	int connect = camera.CameraConnect(&discovery_info[k]);
	//如果connect为0则表示连接成功,如果其他值则表示失败,请查看连接状态或者相机状态灯
	std::cout << "connect=" << connect << std::endl;


	//****************************************获取相机采集到的数据********************************************
	if (connect == 0)
	{
		//获取当前红外相机的宽和高
		int width = -1;
		int height = -1;
		int height_gray = camera.GetCameraHeight(&height, 0);
		int width_gray = camera.GetCameraWidth(&width, 0);
		std::cout << "相机灰度图的宽:" << width << std::endl;
		std::cout << "相机灰度图的宽:" << height << std::endl;


		//定义点云数据大小
		PhotoInfo* point_data = new PhotoInfo;
		point_data->pixel = new char[width * height * 6];
		memset(point_data->pixel, 0, width * height * 6);
		//设置触发模式 0 连拍模式  1 触发模式
		int tirggerMode = camera.SetTriggerMode(1);
		std::cout << "tirggerMode:" << tirggerMode << std::endl;
		//开始点云的数据流通道(1:点云 0:红外 2:RGB)
		int stream_point = camera.StreamOn(1, &pointgigestream);
		std::cout << "stream_point=" << stream_point << std::endl;
		//开始接收数据
		int acquistion = camera.AcquisitionStart();
		std::cout << "acquistion=" << acquistion << std::endl;
		//刷新点云数据流通道缓冲区的数据
		pointgigestream->FlushBuffer();
		//相机固件版本号
		std::cout << "camera 1 version" << camera.CameraVerion(discovery_info[k]) << std::endl;
		//设置触发模式下触发帧数
		int triggerCount = camera.SetTriggerCount();
		std::cout << "triggerCount:" << triggerCount << std::endl;
		//采集点云数据
		int capturePoint = -1;
		capturePoint = pointgigestream->TimeoutCapture(point_data, 3000000);
		std::cout << "capture_Pointimage: " << capturePoint << std::endl;

		//保存点云txt数据格式
		int savepoint_Txt = camera.SavePointCloudToTxt(*point_data, (char*)"1.txt");
		std::cout << "savepoint_Txt: " << savepoint_Txt << std::endl;
		//保存点云pcd数据格式
		int savepoint = camera.SavePointCloudToPcd(*point_data, (char*)"1.pcd");
		std::cout << "savepoint_Pcd: " << savepoint << std::endl;
		//保存点云ply数据格式
		int savepoint_PLY = camera.SavePointCloudToPly(*point_data, (char*)"1.ply");
		std::cout << "savepoint_PLY: " << savepoint_PLY << std::endl;

		memset(point_data->pixel, 0, width * height * 6);
		//释放内存
		delete[] point_data->pixel;
		delete point_data;
		//关闭点云数据流通道
		int streamoff_point = camera.StreamOff(1, pointgigestream);
		std::cout << "streamoff_point=" << streamoff_point << std::endl;
		//断开相机
		int disconnect = camera.CameraDisconnect();
		std::cout << "disconnect=" << disconnect << std::endl;
	}
	return 0;
}

使用D200采集人脸点云效果

知微传感Dkam系列3D相机SDK例程篇:连接相机采集并保存数据_第1张图片

你可能感兴趣的:(3d,c++)