SIMULINK Code Generation with USB Webcam under Ubuntu

Hello everybody,
Please find my complete setup at the bottom of this Post.
i am trying to integrate a USB Webcam in a SIMULINK model from which i want to generate and build a standalone application. I am trying to achieve this by two different ways:
1) Using the "From Video Device Block":
Therefore I simply use this model:
[From Video Device Block]->[Convert 2D to 1D]->[To File block] Building the model succedes but when i am trying to run it with sudo ./model i get: "Could not open library: libmwimaqmex.so" Copying libmwimaqmex.so to the folder where the compiled model lies did not solve the problem.
2) Using a MATLAB function block:
In the MATLAB function block i wrote the following code:
function y = fcn()
%#codegen
persistent vid
if isempty(vid)
vid = imaq.VideoDevice('linuxvideo');
end
img = step(vid);
y = 1;
Trying to build this model results in an error during building:
HostLib_rtw.o: In function `DestroyHostLibrary': HostLib_rtw.c:(.text+0x15): undefined reference to `dlclose' HostLib_rtw.o: In function `CreateHostLibrary': HostLib_rtw.c:(.text+0x93): undefined reference to `dlopen'
I had a look in the generated C files and i found in HostLib_rtw.h: include dlfcn.h So i thought that libdl.so should be linked somewhere.
Does anybody has some experience with this problems?
Here my complete setup:
OS: Ubuntu 14.04 LTS Kernel: 3.7.8-030708-generic (important cause with the kernel brought by 14.04 LTS, the USB Webcam cannot be used even with standard MATLAB Code)
Target: ert_linux.tlc (Downloaded from http://rtime.felk.cvut.cz/~sojka/blog/)

2 Comments

For situation (1) try adding the directory containing libmwimaqmex.so to LD_LIBRARY_PATH
Hey Ketan! thanks for your advices. I have modified my LD_LIBRARY_PATH by adding follwing lines to ~/.bashrc:
export LD_LIBRARY_PATH=/usr/local/MATLAB/R2014a/toolbox/imaq/imaqblks/imaqmex/g$
export LD_LIBRARY_PATH=/usr/local/MATLAB/R2014a/bin/glnxa64:$LD_LIBRARY_PATH
As described below, my model runs now for ever but still the same error is thrown and no mat file is written:
Could not open library: libmwimaqmex.so

Sign in to comment.

Answers (3)

Are you able to run the model using:
>> !sudo ./model
at the MATLAB prompt? If yes, it could be that libmwimaqmex.so needs additional dependencies that were not copied over (within MATLAB, the system PATH is correctly setup). You could try using the packngo utility to grab all dependencies.
Regarding the second issue, what happens if you include libdl.so in the Simulation Target>Custom Code>Libraries pane of the Configuration Parameters window? Also, please check the box that says "Use the same custom code settings as Simulation Target" on the Code Generation>Custom Code pane

3 Comments

Thanks for your reply!
Trying your advise:
>> !sudo ./model
results in the same error than in the ubuntu terminal:
Could not open library: libmwimaqmex.so
I have also checked the location for libmwimaqmex.so:
>> !locate libmwimaqmex.so
/usr/local/MATLAB/R2014a/bin/glnxa64/libmwimaqmex.so
/usr/local/MATLAB/R2014a/toolbox/imaq/imaqblks/imaqmex/glnxa64/libmwimaqmex.so
Checking my LD_LIBRARY_PATH in MATLAB gives me:
!echo $LD_LIBRARY_PATH
/usr/local/MATLAB/R2014a/sys/os/glnxa64:/usr/local/MATLAB/R2014a/bin/glnxa64:/usr/local/MATLAB/R2014a/extern/lib/glnxa64:/usr/local/MATLAB/R2014a/runtime/glnxa64:/usr/local/MATLAB/R2014a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/R2014a/sys/java/jre/glnxa64/jre/lib/amd64/server
So MATLAB should at least know one location of libmwimaqmex.so. I don't know if the other libmwimaqmex.so in /usr/local/MATLAB/R2014a/toolbox/imaq/imaqblks/imaqmex/glnxa64/ is somehow different or necessary too.
For the second issue:
I have already included libdl.so in Code Generation>Custom Code with the correct include directory (libdl.so lies in /usr/lib/x86_64-linux-gnu/) but trying your advise to include it in Simulation Target>Custom Code>Libraries and checking "Use the same custom code settings as Simulation Target" resulted in a succesful build. But now i get again (both in terminal and MATLAB command line) the error:
Could not open library: libmwimaqmex.so
The difference now is that the program keeps running forever and does not return immediatly.
One other maybe interessting fact is that when i am just running this simulation, i get a message in the ubuntu terminal (from which i run matlab):
Could not determine function entry points in libmwimaqmex.so
Any other advices? I am getting really stuck here... In parallel i am working on writing my own s function in C where i grap images from cam via openCV but in my head it doesn't make sense why those matlab boxes just won't work...
Timotheus: I wonder if you are missing some dependency files for libmwimaqmex.so - could you try using the nm or ldd utilities as documented in this solution to see why the OS is having trouble loading the library.
Kaustubha mentioned earlier to use packNGo to get all the needed dependent libraries. Have you tried that for situation (1)? This goes along with the idea of missing dependencies. See the following doc page:

Sign in to comment.

if anybody is interested, i have solved this problem by simply creating a C s function block and grapping from there an image from my usb webcam by using opencv. the other block simply didn't work out
Hi, does your problem got solved. Please help me I am also getting same error. When I run the standalone application generated from video device block . I am getting error of could not determine entry point functions in libmwimaqmex.so

Asked:

on 16 Jun 2014

Answered:

on 2 Mar 2020

Community Treasure Hunt

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

Start Hunting!