0

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

  • Could you explain how exactly is the data acquired as 3D object in Halcon? – Vladimir Perković Nov 10 '22 at 14:45
  • First the camera is open with openframegrabber, some settings, then a GrabDataAsync, and with a SelectObj we select from the Image HTuple the PointCloud (index 2). – Stefano Grossi Nov 11 '22 at 15:39
  • Anyway, i've found a way to solve the problem. the serialized item can be used. `SerializeObjectModel3d(hv_ObjectModel3D, &hv_SerializedItemHandle); GetSerializedItemPtr(hv_SerializedItemHandle, &hv_Pointer, &hv_Size); size_t L = (size_t)(int)(hv_Size); unsigned char* str2 = new unsigned char[L]; memcpy(str2, (unsigned char* )hv_Pointer[0].L(), L); ` after it is received: `CreateSerializedItemPtr((HTuple)(Hlong)str3, hv_Size, "false", &hv_SerializedItemHandle1); DeserializeObjectModel3d(hv_SerializedItemHandle1, &hv_ObjectModel3D1);` This can be applied to any obj in Halcon – Stefano Grossi Nov 11 '22 at 15:41
  • If you've found a solution, please post it as an answer. This is allowed by Stack Overflow rules. – Vladimir Perković Nov 14 '22 at 16:00

0 Answers0