Introduction to Kinect bridge Matlab code KinectBridge With Matlab
Kinect Bridge
With MATLAB & OpenCV introduction documentation and project downloads
Driver version: Kinect for Windows SDK v1.7
Project name: KinectBridgeWithMATLABBasics-D2D
Programming Language: C ++
Environment Configuration
The kinectbridgewithmatlab basics-d2d.doc file in the same sample shows us how to configure the environment. There are two ways to set environment variables. Here I will select the second method for demonstration.
Start ---> right-click my computer ---> properties ---> advanced --> environment variable --> Create a new "system variable" --> Add an environment variable of "MATLAB_DIR" to store the installation address of matlab. Under this address, you can see the extern folder, otherwise it is incorrect.
After the configuration is complete, log out (or restart) before it takes effect.
Because my computer is 64-bit, an error message is displayed after compilation:
1> LINK: fatal error LNK1181: the input file "libmx. lib" cannot be opened"
We need to change the solution platform to x64.
In addition, we can copy the extern folder under matlab from other x32 computers for configuration. For example, I changed the folder copied from x32 to extern32, and then reconfigured the environment. The compilation was successful! [This is not recommended. The following shows that the operation will fail]
Libmx is lost. dll, copied to the path (x32 and x64 are different, please copy it according to the situation, and later found that both can run, do not care) Run, found that the operation failed, specifically, m_matlab engine = engOpen (NULL); failure. After Baidu, we found that the solution should be explain (in fact, it is a statement, but it should be entered in a proper place ):
After the registration is successful, the matlab command line appears. Let's turn it off. If I try to compile the x32 environment on x64 and run it again, the matlab Engine cannot be opened successfully. Only x64 can be used. Therefore, it is better to configure and run your pc. [It is found that libmx. dll can be mixed, whether in the win32 or win64 folder]
Program running and brief explanation
Final running result diagram:
After reading the program, it is very similar to the previous OpenCV and runs the same process: Upload the image obtained by the SDK to the mxArray structure of Matlab, and then call the Matlab evalexpr (execute the string Statement) perform Various operations on it.
Example:
Const
Char * c_erodeElementExpr = "filtered_img = imerode (img, se );";
Hr = maid (c_erodeElementExpr );
That is to say, the hybrid programming of matlab is used, only functions or methods in matlab are used, but the main upper-layer coding work still needs to be completed by C ++. If you already have good matlab algorithm code, just want to see the results of the Kinect data running, then use this hybrid programming method to run the algorithm, you can get the expected results. Currently, in this c ++ example, the skeleton tracking is not added (such a core function). You can consider adding this function on your own.
I also want to say that this is just a new example. If mixed programming is used, a similar or better example can be written more than a year ago.
The mxArray structure where data is stored in matlab can be viewed as a function:
Hresultmatlab framehelper: GetColorData (mxArray * pImage)
Const
Hresultmatlab framehelper: GetDepthData (mxArray * pImage)
Const
If you have previously written matlab hybrid programming, you must be familiar with these functions (functions starting with mx.
Since Matlab is not used for detailed research, we will not explain it in depth. If you are not running successfully, leave a message. You are welcome to follow my microblog, Song mingqin, playing the _ CPP program Xia.
Matlab Engine
Http://www.cnblogs.com/jiajinwen/archive/2012/04/13/2257644.html