-1

I'm having a problem with Index_Faces using Amazon aws-cpp-sdk. I'm getting segmentation fault in following program.

Image *fileData;

Image& imageToBytes(const char* str)
{
    FILE *fp;
    size_t length = 0;

    fp= fopen(str, "rb");
    if(fp == NULL)
    {
        exit(0);
    }
    fseek(fp, 0, SEEK_END);
    length= ftell(fp);
    rewind(fp);
    fileData= (Image*)malloc((length+1)*sizeof(char));
    fread(fileData, length, 1, fp);
    return *fileData;
}

int main()
{
   Aws::SDKOptions options;

   Aws::InitAPI(options);
   {
       RekognitionClient *rekClient = new RekognitionClient();
       CreateCollectionRequest *clRequest = new CreateCollectionRequest();

       CreateCollectionRequest str = clRequest->WithCollectionId("collection7981");

       CreateCollectionOutcome respose = rekClient->CreateCollection(str);
       std::cout<<"Collection Successfully Created..."<<std::endl;

       IndexFacesRequest iFaceRequest;

       iFaceRequest.WithImage(imageToBytes("/home/msc/Profile_Pics/ms.JPG"));

   }
   Aws::ShutdownAPI(options);
   return 0;
}

So, how to provide an image file from my local system to amazon aws-cpp-sdk?

msc
  • 33,420
  • 29
  • 119
  • 214

1 Answers1

3

You can't create c++ classes with malloc(well actually you can but you need to call the constructor afterwards). You need to use new instead which calls the constructor for you.

There are 4 different classes called "Image" in aws-cpp-sdk, none of them are suitable for passing directly to fread.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60