Forums - How to use UserBuffer in C++

4 posts / 0 new
Last post
How to use UserBuffer in C++
sohan
Join Date: 19 Aug 20
Posts: 5
Posted: Thu, 2022-10-20 03:26

I have RAW frame data in an unsigned char* array. I want to convert it to UserBuffer and then push it to the model. The example provided in the SNPE SDK reads a file and then use it. I am not sure how to use the UserBuffer in the right way. 

Can anyone help me with that?

  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Sat, 2022-10-22 10:19

Dear developer,

You can review the source cpp code at main.cpp for line of  createInputBufferMap(inputMap, applicationInputBuffers, snpeUserBackedInputBuffers, snpe, true, bitWidth);

This interface was defined at CreateUserBuffer.cpp.

Please help to take a look at above definition.

BR.

Wei

  • Up0
  • Down0
sohan
Join Date: 19 Aug 20
Posts: 5
Posted: Mon, 2022-10-24 22:03

Hello Wei,
Thanks for your response.
This is the code I found to get the result of the detection. The result is written in raw format. I am not sure, in which index there is bounding boxes, labels or confidence. There is no documentation or any instruction about this. Can you please help me with that?
BR,
Sohan

bool SaveUserBufferBatched(const std::string& path, const std::vector<uint8_t>& buffer, size_t batchIndex, size_t batchChunk)
{
   if(batchChunk == 0)
      batchChunk = buffer.size();
   // Create the directory path if it does not exist
   auto idx = path.find_last_of('/');
   if (idx != std::string::npos)
   {
      std::string dir = path.substr(0, idx);
      if (!EnsureDirectory(dir))
      {
         std::cerr << "Failed to create output directory: " << dir << ": "
                   << std::strerror(errno) << "\n";
         return false;
      }
   }
 
   std::ofstream os(path, std::ofstream::binary);
   if (!os)
   {
      std::cerr << "Failed to open output file for writing: " << path << "\n";
      return false;
   }
 
   for ( auto it = buffer.begin() + batchIndex * batchChunk; it != buffer.begin() + (batchIndex+1) * batchChunk; ++it )
   {
      uint8_t u = *it;
      if(!os.write((char*)(&u), sizeof(uint8_t)))
      {
        std::cerr << "Failed to write data to: " << path << "\n";
        return false;
      }
   }
   return true;
}
  • Up0
  • Down0
SahilBandar
Join Date: 23 May 18
Posts: 37
Posted: Tue, 2022-12-13 00:08

Hi Sohan,

You can use the createUserBuffer API from SNPE C++ Native API to create your own custom input buffer.
Please take a look into the documentation in below link for the same,
https://developer.qualcomm.com/sites/default/files/docs/snpe/group__c__p...

Also you can use the createTensor API for the same,
For more detailed understanding, go through the sample implemented for your reference,
https://github.com/globaledgesoft/person-detection-snpe-ros2-cpp-api-rb5...

Regards,
Sahil Bandar

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.