OpenCV configuration

This is more a general than a Toradex specific question. Would like to configure opencv with only core, imageproc and freetype. Building opencv takes some time, so best would be to configure not only the image itself but the build process. How can I do that that only these 3 packages are build. And -bonus question- how to build this libs as static one. I need to include them into an SDK for the team. Thanks ahead for any help.

Hi @Steven1 !

If I understood correctly, you want to shorten the build time and also make your image lighter, right?

AFAIK, the answer relies on knowledge of the PACKAGECONFIG of OpenCV and knowledge of OpenCV’s configuration/build itself. I can help you a bit with the former, but the latter is OpenCV’s specific build knowledge and I have never played around with it.

Supposing you are using Toradex’s BSP 6 (Yocto Kirstone), and looking for OpenCV’s recipe(s), we get:

https://layers.openembedded.org/layerindex/branch/master/recipes/?q=opencv

To me, from the results above, seems like these two are the most interesting:

The second one is the i.MX fork of OpenCV and seems to be more interesting, as you are using an i.MX SoC (Apalis iMX8). It is worth noticing that this fork doesn’t exist for Yocto Dunfell (version 3.1), as we can see on its page above.

Its recipe is here: opencv_4.6.0.imx.bb « opencv « recipes-support - meta-freescale - Layer containing NXP hardware support metadata

You can check all the PACKAGECONFIG[xxx] lines to see which build options you have available in this recipe and then check the PACKAGECONFIG ??= ... (line 118) to see which of the available build options are actually enabled.

We can right away see that freetype is a build option (line 133), but it is not enabled (line 118). So, to enable freetype, you need to add it to the PACKAGECONFIG in line 188.

As for the core and imageproc, you need to find out which of the build options in the recipe will enable them and you can (hopefully) remove all the other build options from the PACKAGECONFIG.

I hope this helps you :slight_smile:


This part I didn’t quite understand… after configuring your recipes/layers as you need, the process of building your own SDK would give you the toolchain you need to build an application for the image you built with Yocto. Here is a helpful article about it: Linux SDKs | Toradex Developer Center

Let me know if I misunderstood something.

Best regards,

Thanks Henrique, I use the meta-oe version, exactly 4.5.5 (yocto 4.0.5).
My focus was PACKAGECONFIG too. But all my attempts to change that via bbappend failed.
In bb file there is a line
PACKAGECONFIG ??= “gapi …” so I though it should be sufficient to have in bbappend file:
PACKAGECONFIG = “freetype”
But neither adding nor removing others seems to work. (I have to repeat whether it gets ignored or result in a failure, guess last one.)
But in one step it fails (configure, compile or install) with a (for me) not understandable error. I will repeat that and update this post.
Also PACKAGECONFIG:remove:pn_opencv = “gapi …”
PACKAGECONFIG:remove = “gapi …” doesn’t work.

I got freetype to be added by an
EXTRA_OECMAKE:append = " -DWITH_FREETYPE:BOOL=on
-DBUILD_opencv_freetype:BOOL = on
"
But remove other parts this way again failed.

About the second “bonus” question. By default and with -c populate_sdk the libs will be build as shared libs. As I need only very few functions from opencv I thought it might be cute to have static libs. Than only required parts will be compiled into my app and the footprint of filesystem will be smaller. Just as an idea.

Tried again with a single line in bbappend:
PACKAGECONFIG = “freetype”
I can see that none of the mentioned packages in bb (gapi …) has been build, but neither freetype. So still 87 packages - much more than I need, but less then the 96 without that bbappend. (Without counting that I wouldn’t notice the difference.)
Nevertheless: freetype package has not been build !?!

And: each little change in bbappend causes a new compile for for quite some time. You have to do a clean inbetween otherwise it creates error while the install.

EdIt:
To add freetype I need the above mentioned lines in OECMAKE - but that doesn’t work with PACKAGECONFIG - neither “freetype” or “” . So the number of packages is even > 87.
It drives me nuts.

Hi @Steven1!

Sometimes it takes us a while to understand what is going on and I know how frustrating it can be :sweat_smile:

When you run any recipe task in Yocto, you can actually check what is being performed under the hood.

For example, for the do_configure task of a recipe, you can go to e.g. build/tmp/work/cortexa72-cortexa53-mx8-tdx-linux/opencv/4.5.5-r0/temp/log.do_configure. From there you can check the configuration applied to OpenCV.

If the current recipe is not suitable for you you will need to make changes (or a bbappend) to it. If you find your changes really useful, you can even submit them to the upstream repository of the recipe.

This OpenCV Github Wiki page seems you be useful to better understand what you can tweak in an OpenCV build:

Best regards,

Hi @Steven1!

Two more comments:

Best regards,

Thanks for your help. I will check that next again. If I found a solution I will post it - maybe it will help others too.

Hi @Steven1 !

It would be great :slight_smile:

Best regards,