i am writing a code in C++ that acquires data from a 2D or 3D sensor (for example Photoneo XL) and has the aim to save the image/point cloud in MongoDB through Gridfs(this requires to serialize the data in a buffer of unsigned char*) because data are greater that 16MB. I can not save the image/pointcloud to file because it would take too much time, therefore I need to take the sensor output variable and convert it in bytes.
As an overview of the solution, the final software is a microservices based software, in which there is a service that acquires the image/point cloud and uploads it to Mongo. Then, other microservices could access MongoDB instance and access the image/pointcloud through the ID reference.
For what regards the images, i have something similar that has solved the problem:
QImage img = QImage("./smallimage.png");
mongocxx::gridfs::bucket bucket = db.gridfs_bucket();
auto uploader = bucket.open_upload_stream("sample_gridfs_file");
uploader.write((unsigned char*)img.bits(), img.sizeInBytes());`
Then, following the example of gridfs, i can read the buffer and decode it in the image:
while (auto length_read = downloader.read(buffer.get(), static_cast<std::size_t>(buffer_size)))
{
bytes_counter += static_cast<std::int32_t>(length_read);
tmp_char = (unsigned char*)buffer.get();
memcpy(array_char+cum_size,tmp_char, buffer_size);
cum_size += buffer_size;
}
QImage out = QImage(array_char, img.width(), img.height(), img.format());
I am in trouble with the point cloud. It is acquired through Halcon, then I have an HTuple that contains the 3D object info. In order to simplify the problem, I can extract just 3 double* containing the points in X, Y, Z. I would like to serialize these information in an unsigned char*, load it in mongo and then read and decode the information in 3 new double*, to recreate the point cloud.
The starting code is down here:
HalconCpp::ReadObjectModel3d("./point_cloud.ply", "m", HalconCpp::HTuple(), HalconCpp::HTuple(),&hv_ObjectModel3D, &hv_Status);
HalconCpp::GetObjectModel3dParams(hv_ObjectModel3D, "num_points", &numPoints);
HalconCpp::GetObjectModel3dParams(hv_ObjectModel3D, "point_coord_x", &pointsX);
HalconCpp::GetObjectModel3dParams(hv_ObjectModel3D, "point_coord_y", &pointsY);
HalconCpp::GetObjectModel3dParams(hv_ObjectModel3D, "point_coord_z", &pointsZ);
double* xArray = pointsX.DArr();
double* yArray = pointsY.DArr();
double* zArray = pointsZ.DArr();
Thank you in advance for the support