编码CV_32FC1使用base64填充数据 [英] Encoding CV_32FC1 Mat data with base64

查看:527
本文介绍了编码CV_32FC1使用base64填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello我试图从SURF描述符中提取数据,当我尝试这个与ORB描述符它工作。当我使用SURF一个程序退出与base64编码行上的分段错误11,我使用base64函数从这个网站:编码和解码base64

Hello I am trying to extract the data from a SURF descriptor, when I try this with an ORB descriptor it works. When I use the SURF one the program quits with a segmentation fault 11 on the base64 encode line, I use the base64 function from this site: Encoding and decoding base64.

确切的问题是ORB描述符的格式是 CV_8UC1 和SURF描述符 CV_32FC1 。所以我必须base64编码一个32位浮点而不是一个8位无符号字符。

The exact problem is that the format for the ORB descriptor is CV_8UC1 and the SURF descriptor CV_32FC1. So I must base64 encode a 32 bit float instead of a 8 bit unsigned char.

我该如何做?

Mat desc;
vector<KeyPoint> kp;

SurfFeatureDetector detector(500);
SurfDescriptorExtractor extractor;
// OrbDescriptorExtractor extractor; This works

detector.detect(image, kp);
extractor.compute(image, kp, desc);

desc.convertTo(desc, CV_8UC1, 255, 0);

unsigned char const* inBuffer = reinterpret_cast<unsigned char const*>(desc.data);
unsigned int in_len = desc.total();
string code = base64_encode(inBuffer, in_len).c_str(); // This line causes the error


推荐答案

问题可能是你不使用之前检查 inBuffer NULL 值。如果没有从传入的映像生成描述符, desc.data ,并通过扩展 inBuffer code> NULL 。

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.

还有几件事:


  1. 使用 reinterpret_cast 是不必要的,很可能不安全。请参见此问题铸造类型的解释。如果你想要一个指向描述符数据的const指针,你可以这样简单地赋值:

  1. 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使用 float 描述符,而ORB使用二进制描述符。如果您打算使用SURF,您可能需要更改您的代码。 inBuffer 的分配可以更改为

  • SURF uses float descriptors, while ORB uses binary descriptors. If you intend to use SURF, you may need to change your code. The assignment of inBuffer could be changed to

    const float* inBuffer = reinterpret_cast<const float*>(desc.data);
    

    在这种情况下,使用 reinterpret_cast 适当。然而,可能是建议避免做直接指针操作,除非你真的必须。请考虑使用 cv :: Mat_< float> 进行元素访问。

    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 using cv::Mat_<float> for element access.

    编辑:根据更新的问题,点2的相关性较低。另外一个问题出现:从 float 转换为 uchar 通过 convertTo()将丢失信息。在这种情况下,转换将使描述符数据的原始精度不可恢复。可以像以前一样简单地处理描述符数据,假设您的base64编码工作,但这超出了这个问题的范围。

    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.

    这篇关于编码CV_32FC1使用base64填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆