Ask Your Question

Cannot run a script that executes my opencv program at startup under Linux

asked 2016-06-13 09:50:54 -0500

Major Squirrel gravatar image

updated 2016-06-13 12:20:43 -0500

Hi there,

I would need some help there.

I'm trying (since this morning) to make a script that can launch my opencv program at startup. The script does work well :


export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/lemaker/Documents/Project/opencv/install/lib


As you can see (or not), I work on a LeMaker Guitar using Ubuntu Mate.

EDIT: The thing is, the opencv_program doesnt start at startup, trying to check if it had started using htop or top. In fact, I don't even know if my script is ok, I mean : I don't have any mean to check any debug messages or something.

I explored many solutions :

  • Launching my script from /etc/rc.local
  • Launching my script as a Linux service
  • Launching my script with crontab -e
  • Launching my script after X started (in /etc/X11/xinit/xinitrc)

It does just not work. When, in my script, I put some basic commands like creating a file or something, it works. But when I try to launch my program, only its line does not work. I have to export a library path because I compiled opencv as shared libs.

I tried to do it with sudo :


sudo -s <<EOF

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/lemaker/Documents/Project/opencv/install/lib



This does not work too. I suspect that I have to launch my program with specific requirements but I can't find out which ones. Do I need to run my script after X started, or something ? Do you guys have any experience in launching an opencv program at startup ?

Could you please guide me ?

Thank you in advance, and have a good day !

edit retag flag offensive close merge delete


long post, but you never say, what's going wrong

berak gravatar imageberak ( 2016-06-13 11:33:27 -0500 )edit

@berak Edited !

Major Squirrel gravatar imageMajor Squirrel ( 2016-06-13 12:21:03 -0500 )edit

BTW, you can check with ps -A if your program is running. For debug messages use a logfile if you don't have a display connected (or direct access to console messages).

kbarni gravatar imagekbarni ( 2016-06-14 02:34:12 -0500 )edit

BTW, off-topic question: what is your experience with the LeMaker Guitar board? I read very bad reviews about the Linux support of the BananaPi board (from the same company) and it's the weak point of most cheap chinese ARM boards.

kbarni gravatar imagekbarni ( 2016-06-14 04:02:00 -0500 )edit

@kbarni Regarding hardware components, I'm not disappointed because it is hard to find good components like Cortex-A9 and PowerVR SGX544 with this price. But you're right, I feel that I have many problems with Ubuntu MATE on this board, + the support is awful (the hotline doesn't even speak english)

For now, I have bad results with opencv but I think that it is my fault : I suppose that I don't use the full potential of this board for opencv. (I need to learn about NEON and VFP + OpenCL hardware acceleration)

Major Squirrel gravatar imageMajor Squirrel ( 2016-06-16 10:15:30 -0500 )edit

Thanks for the feedback about the Lemaker Guitar! I think that the Raspberry Pi 3 is still unbeatable, as it's quite cheap, powerful, it has excellent software support and a good community.

As these boards have several cores, I prefer to parallelize the processing on the CPUs rather than going OpenCL, which can be a real PITA to debug. I suggest to use the TBB library, if it's available in the repositories.

kbarni gravatar imagekbarni ( 2016-06-16 11:19:26 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-06-16 10:20:50 -0500

Major Squirrel gravatar image

Thanks to @kbarni, I was able to make it work :

With Ubuntu MATE on Le Maker Guitar (so, specific hardware + distro), putting my application in "Startup Applications" seems to not work at all. I gave a try at Upstart, rc.local and runlevels init, without success. However, I was able to make my own systemd user service to start my application.

This link helped me to build my service step by step : (take a look at the whole help page to use the full potential of systemd)

You should be able to make your service work for a specific user by taking a look at this link :

(Don't know why, hyperlink doesn't work on the forum right now)

edit flag offensive delete link more

answered 2016-06-13 11:50:22 -0500

kbarni gravatar image

Normally OpenCV programs should run on Linux systems, even on startup.

If you aren't using any graphical elements (like imshow), it should work without X server, too.

I think, it's a good idea to launch the program as a user process, not as a (systemd or init.d) service. Don't use sudo, as it's not intended to run your programs.

If you want to launch it without X server, put a line at the end of the .profile file:


Otherwise the easiest solution is to add it to the Startup programs (you'll find it in Settings).

If you want to autostart the program at boot, just enable autologin.

Note that it's a good idea to add the OpenCV lib folder to a file in the /etc/ folder (and run ldconfig), so you don't have to export the library path every time

edit flag offensive delete link more


Hi @kbami

I tried to run my application from "Startup Applications" or as Upstart : it works on my Ubuntu 64 bits but it doesn't on my LeMakerGuitar with Ubuntu MATE arm.

It just doesn't launch, and I don't know why. At first I thought it was opencv fault with dynamic linking, but it seems not. In fact, it seems that it doesn't launch my program because it doesn't start it in any session.

Major Squirrel gravatar imageMajor Squirrel ( 2016-06-14 03:28:33 -0500 )edit

Normally there is no difference between running your app on a 64bit or ARM Ubuntu. The problem is probably elsewhere (libraries not found, etc). I often use ARM boards in headless configurations that only launch OpenCV program for automatic processing without problems

Try to write a startup script (, and check first if it works. Then add it to startup applications. Check with a logfile if started, and if opencv_program runs and where it crashes (by adding debug messages).

Try to launch a simple C program at startup, then add libraries like OpenCV. Go step by step; we can't figure out what doesn't work on your exotic ARM board.

kbarni gravatar imagekbarni ( 2016-06-14 03:49:42 -0500 )edit

Question Tools

1 follower


Asked: 2016-06-13 09:50:54 -0500

Seen: 1,810 times

Last updated: Jun 16 '16