For a course imaging processing I am building a Matlab/C++ application. Matlab should recognize hand gestures, and it should sent them to the C++ application. Our idea was to create a queue in matlab which we can read from C++. This works perfectly, however we have one problem:
We get the data from the webcam in an infinite while loop. Inside that loop we use assignin(‘base’,….) and evalin(‘base’,…) to send our commands to the workspace. However, those commands are only send after the loop has finished by clicking our stop button. This means that the C++ application can’t read the values realtime, it can only read the values after we stopped the image processing alltogether.
So is it possible to force matlab to write the variables to the base workspace so we can read those values with the c++ application from matlab?
EDIT:
Below a short description of how the program works:
The application start with the C++ application. The C++ application starts the Matlab engine, and calls the initialization script of the Matlab application. The initialization script starts a GUIDE gui, and by a press on a button the gesture recognition part starts. The gesture recognition part of the Matlab application is an infinite while loop which continuously gets a frame from the webcam input and processes that image. When a gesture is found, it uses evalin to write the gesture ID to a queue in the base workspace. Meanwhile the C++ application is also in an infinite loop which continuously checks if there are items in that Matlab queue. However, it won’t find any items until the Matlab script gets out of that while loop.
When I add items to the queue manually the C++ application will read those values immediately, and when I don’t use a while loop to capture frames continuously but a button to get individual frames manually the C++ application can also read the values immediately. So it seems that the while loop is blocking the C++ application to read the queue.
The solution I’ve created was quite simple: I put everything inside the while loop in a seperate function, and called that function every frame-update of the c++ application, instead of having 2 separate while loops.