One source of your problems could be you do not check inBuffer
for NULL
values before you use it. If no descriptors were generated from the image you pass in, desc.data
, and by extension inBuffer
, will be NULL
.
A few more things:
Your use of
reinterpret_cast
is unnecessary, and quite possibly unsafe. See this question for a good explanation of cast types. If you want a const pointer to the descriptor data, you can simply assign one like so:const uchar* inBuffer = desc.data;
SURF uses
float
descriptors, while ORB uses binary descriptors. If you intend to use SURF, you may need to change your code. The assignment ofinBuffer
could be changed toconst float* inBuffer = reinterpret_cast<const float*>(desc.data);
In this case the use of
reinterpret_cast
may be appropriate. However, it might be advisable to avoid doing the direct pointer manipulation unless you really have to. Consider usingcv::Mat_<float>
for element access.
EDIT: In light of the updated question, point 2 is less relevant. An additional issue arises: Converting from float
to uchar
via convertTo()
will lose information. In this case, the conversion will make the original precision of the descriptor data unrecoverable. It may be possible to simply treat descriptor data as before, assuming your base64 encoding works, but that is beyond the scope of this question.