How to convert an OpenCV cv::Mat into a float* that can be fed into Vlfeat vl_dsift_process ?

Question:

How to convert an OpenCV cv::Mat into a float* that can be fed into Vlfeat vl_dsift_process? I cannot understand how vl_dsift_process works on a one-dimensional float array. The official samples only demonstrate how to use MatLab API. It seems that there are no samples about C API, and the only clue is the MEX file in the source package.


Answer:

float* matData = (float*)myMat.data;

Make sure the matrix is not deleted/goes out of scope before finishing using the pointer to data. And make sure the matrix contain floats.


I cannot understand how vl_dsift_process works on a one-dimensional float array

DSIFT expects a grayscale image where intensivity of pixel (x, y) is stored in float_array[y * width + x] as float value. In OpenCV images are stored as unsigned chars so simple conversion of Mat::data to float* will not work. You have to manually convert every value to float:

Mat mat = imread("image_name.jpg", 0); // 0 stands for grayscale

vector<float> img;
for (int i = 0; i < mat.rows; ++i)
  for (int j = 0; j < mat.cols; ++j)
    img.push_back(mat.at<unsigned char>(i, j));

vl_dsift_process(dsift, &img[0]);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值