How to convert an OpenCV cv::Mat into a float* that can be fed into Vlfeat vl_dsift_process ?
2013-07-03 02:38
489 查看
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 arrayDSIFT 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:
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 arrayDSIFT 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]);
相关文章推荐
- qt - How can I convert a QImage of format RGB32 to OpenCV::mat? - Stack Overflow
- 在VLFEAT中mat类型图片转换成constant float* 来进行vl_dsift_process
- Gson is a Java library that can be used to convert Java Objects into their JSON representation.
- How to Write a Killer Software Testing QA Resume That Will Turn Into an Interview Call
- How can I convert a floating-point value to an integer in C?
- How to convert an OpenCV IplImage to an SDL_Surface?
- How to import dll in c# that can be accessed by [DllImport]
- How can I convert a floating-point value to an integer in C?
- How to convert an IPv4 address into a integer in C#?
- How to design a class that can't be inherited(C++)
- 如何使用OpenCV的处理图像,文字变得锐利和清晰?(How to use OpenCV to process image so that the text become sharp and clea
- How to design a class that can't be inherited(C++)
- Move can only be called on an active agent that has been placed a Navmesh的解决办法
- How can I deliver parameters to a test function, that launched using adb shell am Instrumentation co
- How To Be an Effective Team Member
- The package needs to be reinstalled, but I can't find an archive for it.
- How do I convert an IIR filter into a FIR filter in digital signal processing?
- BUG "SetDestination" can only be called on an active agent that has been place
- OpenCV怎么画箭头(How to draw an arrow)
- How does Spring know that ThrowsAdvice.afterThrowing needs to be called?