12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #include "mqtt_communication.h"
- void Tof3DMqttAsyncClient::init(const std::string &file) {
- m_message_arrived_callback_ = CloudDataArrived;
- MqttAsyncClient::init_from_proto(file);
- condit = new Thread_condition();
- t = new std::thread(&Tof3DMqttAsyncClient::run, this);
- condit->notify_all(true);
- }
- // 识别结果数据包含识别结果、时间序号、具体识别信息
- int Tof3DMqttAsyncClient::CloudDataArrived(void *client, char *topicName, int topicLen,
- MQTTAsync_message *message) {
- std::string topic = topicName;
- if (topic == "tof/seg") {
- JetStream::LabelYolo seg_results;
- seg_results.ParseFromArray(message->payload, message->payloadlen);
- LabelYoloDataBuffer::iter()->lock_exe(&LabelYoloDataBuffer::set, seg_results);
- }
- return 1;
- }
- void Tof3DMqttAsyncClient::run() {
- std::this_thread::sleep_for(std::chrono::milliseconds(3000));
- auto t_start_time = std::chrono::steady_clock::now();
- std::chrono::duration<double> cost = std::chrono::steady_clock::now() - t_start_time;
- while (condit->is_alive()) {
- condit->wait();
- cost = std::chrono::steady_clock::now() - t_start_time;
- std::this_thread::sleep_for(std::chrono::milliseconds(100 - std::min<int>(99, cost.count() * 1000)));
- t_start_time = std::chrono::steady_clock::now();
- if (condit->is_alive()) {
- static int lable = 0;
- if (lable++ > 1000) {
- lable = 0;
- }
- // 1、获取图片并合并
- cv::Mat merge_mat = cv::Mat::zeros(480 * 2, 640 * 2, CV_8UC1);
- DeviceTof3D::DeviceTof3DSaveInfo devices_info[DeviceAzimuth::DEVICE_AZIMUTH_MAX];
- for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
- devices_info[device_index] = DeviceTof3D::iter()->getDeviceSaveInfo((DeviceAzimuth) device_index);
- MatDataBuffer::iter()->lock_exe(&MatDataBuffer::set, device_index, lable, devices_info[device_index].pointMat);
- devices_info[device_index].irMat.copyTo(merge_mat(cv::Rect((device_index & 0x1) * 640,
- ((device_index & 0x2) >> 1) * 480, 640, 480)));
- }
- JetStream::LabelImage testimage;
- NetMessageTrans::lableMat2Proto(lable, merge_mat, testimage);
- int size_1 = testimage.ByteSizeLong();
- unsigned char data[size_1];
- testimage.SerializeToArray((void *)data, size_1);
- SendMessage("tof/ir", data, size_1);
- }
- }
- }
|