How OpenCV interface can be used with simulink?

1 view (last 30 days)
I am comfortable to use OpenCV interface with Matlab.
But don't know how to use it with Simulink. (For further building).
Anyways my c++ function(imdecode.cpp) which works on matlab is
#include "opencvmex.hpp"
#include "opencv2/imgcodecs.hpp"
#define _DO_NOT_EXPORT
#if defined(_DO_NOT_EXPORT)
#define DllExport
#else
#define DllExport __declspec(dllexport)
#endif
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);
}
Any help !!

Answers (1)

Vijaya Lakshmi Chagi
Vijaya Lakshmi Chagi on 14 Mar 2019
MATLAB provides an API to interface with OpenCV functions with mxArrays. Using the Simulink input/output ports, you will need to create mxArrays. You can use the following link to create mxArrays depending on the input types.
You can use the OpenCV functions to convert data types and then call the OpenCV C++ functions. Once you generate output from the C++ functions, you can pass it to Simulink Outputs using S-function API calls.
The other workflow is to bring existing OpenCV files/projects into MATLAB using Mex. Then use the MATLAB function block to call the generated mex file in Simulink
  1 Comment
madhan ravi
madhan ravi on 14 Mar 2019
@Vijaya your second link works but the content seem to not exist.

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!