MATLAB Answers


How to generate mex for openCV's 'imdecode' for CPU and GPU?

Asked by JAI PRAKASH on 13 Jan 2019
Latest activity Commented on by JAI PRAKASH on 28 Jan 2019
I want to generate mex funtion for 'imdecode'.
First for CPU and then for GPU(GPU, if possible).
I have already downloaded 'OpenCV Interface Support'. But it lacks in some libraries. E.g. mexOpenCV.m shows..
% Libraries that are not included:
% opencv_highgui, opencv_imgcodecs, opencv_videoio, opencv_cudacodec
And I think, openCV's 'imdecode' contains in "opencv_highgui, opencv_imgcodecs".
How can this libraries be added permanently in MATLAB?
Is it possible to avail GPU performance benefits for this particular purpose?
Thank you


Sign in to comment.




2 Answers

Answer by Hitesh Kumar Dasika on 18 Jan 2019

Some libraries are not included because of dependency on other third party libraries. The functionality offered by these libraries can also be found in Image processing toolbox as well. You can make use of that.


I want to decode jpg data.
Jpg data which are in 'uint8' bits form.
In openCV imdecode is designed for this purpose. But I am searching for a function which can give better performnace than imdecode.
I searched 'MANGO' library is fastest.
Is there any way I can use mango library through MATLAB?
You can make use of the below mentioned MATLAB function to load a C library into MATLAB and use it.

Sign in to comment.

Answer by Joss Knight
on 19 Jan 2019

You can just download and use OpenCV yourself, and link in whatever libraries you need on the compile line. This blog post gives an example; it's a bit out of date because it uses MEX instead of MEXCUDA (so now you don't need to copy across the mex options file) but it's a workflow you can follow.

  1 Comment

How can I use nvJPEG libraries to decode image from jpeg's buffer?
e.g. nvjpegDecode(); and so on....??
I can do this easily using OpenCV lib, below is my 'imdecode.cpp'
#include "opencvmex.hpp"
#include "opencv2/imgcodecs.hpp"
#define _DO_NOT_EXPORT
#if defined(_DO_NOT_EXPORT)
#define DllExport
#define DllExport __declspec(dllexport)
using namespace cv;
using namespace std;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
cv::Ptr<cv::Mat> rawData = ocvMxArrayToImage_uint8(prhs[0]);
Mat frame = imdecode(*rawData, -1);
plhs[0] = ocvMxArrayFromImage_uint8(frame);
An then compiling and calling
mexOpenCV imdecode.cpp
im=imdecode(bufferData); % bufferData is bits in uint8

Sign in to comment.