Wednesday, February 26, 2014

Building OpenCV-2.4.X for Freescale's i.MX6 BSP (Yocto)

Lately a lot of people are working with the Yocto Project and many of them migrated from LTIB (like me). Yocto uses a different conception when adding new packages/applications to the system, now everything is based on RECIPES. As it is being highly used, the amount of packages (recipes) already included is very big and it keep increasing continuously. For our lucky the recipe for OpenCV is already there, we just need to configure the system in order to add it to us.

In order to get everything up running we will divide de taks in steps:


Step #1 - Installing Yocto
--------------------------

As our focus is to install OpenCV, the Yocto install procedure we can use this very good tutorial created by Daiane: https://community.freescale.com/docs/DOC-94849


Step #2 - Enabling OpenCV
----------------------------

As we already have the OpenCV recipe in our Yocto release, we just need to add what packages we want in our local.conf file, located at /yocto/fsl-community-bsp/build/conf. With some modification (opencv package), it should look like this:

    MACHINE ??= 'imx6qsabresd'
    DISTRO ?= 'poky'
    PACKAGE_CLASSES ?= "package_rpm"
    EXTRA_IMAGE_FEATURES = "debug-tweaks dev-pkgs"
    USER_CLASSES ?= "buildstats image-mklibs image-prelink"
    PATCHRESOLVE = "noop"
    BB_DISKMON_DIRS = "\
    STOPTASKS,${TMPDIR},1G,100K \
    STOPTASKS,${DL_DIR},1G,100K \
    STOPTASKS,${SSTATE_DIR},1G,100K \
    ABORT,${TMPDIR},100M,1K \
    ABORT,${DL_DIR},100M,1K \
    ABORT,${SSTATE_DIR},100M,1K" 
    PACKAGECONFIG_pn-qemu-native = "sdl"
    ASSUME_PROVIDED += "libsdl-native"
    CONF_VERSION = "1"

    BB_NUMBER_THREADS = '4'
    PARALLEL_MAKE = '-j 4'

    DL_DIR ?= "${BSPDIR}/downloads/"
    ACCEPT_FSL_EULA = ""

    CORE_IMAGE_EXTRA_INSTALL += "gpu-viv-bin-mx6q gpu-viv-bin-mx6q-dev"
    CORE_IMAGE_EXTRA_INSTALL += "libopencv-core-dev libopencv-highgui-dev
libopencv-imgproc-dev libopencv-objdetect-dev libopencv-ml-dev"

    LICENSE_FLAGS_WHITELIST = "commercial"


Note that we included the "-dev" packages, this is necessary if you always want to have the OpenCV headers/libraries included in the rootfs, Yocto is smart if you don´t add a "-dev" package and the libraries are just included any application that uses it needs to be built. As we always want our OpenCV stuff to build our applications so we use it this way.


Step #3 - Building OpenCV
----------------------------

Now the easy part:

/yocto/fsl-community-bsp/build$./bitbake core-image-x11

after build is finished you can check the images generated by the bitbake command at:

/build/tmp/deploy/images/imx6qsabresd/

and after extracting the rootfs: core-image-x11-imx6qsabresd.tar.bz2, you can find the opencv libraries in the /usr/lib folder:

andre@b22958:~/bsps/yocto/rootfs$ ls usr/lib/libopen*
usr/lib/libopencv_calib3d.so           usr/lib/libopencv_ml.so
usr/lib/libopencv_calib3d.so.2.4       usr/lib/libopencv_ml.so.2.4
usr/lib/libopencv_calib3d.so.2.4.7     usr/lib/libopencv_ml.so.2.4.7
usr/lib/libopencv_contrib.so           usr/lib/libopencv_nonfree.so
usr/lib/libopencv_contrib.so.2.4       usr/lib/libopencv_nonfree.so.2.4
usr/lib/libopencv_contrib.so.2.4.7     usr/lib/libopencv_nonfree.so.2.4.7
usr/lib/libopencv_core.so              usr/lib/libopencv_objdetect.so
usr/lib/libopencv_core.so.2.4          usr/lib/libopencv_objdetect.so.2.4
usr/lib/libopencv_core.so.2.4.7        usr/lib/libopencv_objdetect.so.2.4.7
usr/lib/libopencv_features2d.so        usr/lib/libopencv_ocl.so
usr/lib/libopencv_features2d.so.2.4    usr/lib/libopencv_ocl.so.2.4
usr/lib/libopencv_features2d.so.2.4.7  usr/lib/libopencv_ocl.so.2.4.7
usr/lib/libopencv_flann.so             usr/lib/libopencv_photo.so
usr/lib/libopencv_flann.so.2.4         usr/lib/libopencv_photo.so.2.4
usr/lib/libopencv_flann.so.2.4.7       usr/lib/libopencv_photo.so.2.4.7
usr/lib/libopencv_gpu.so               usr/lib/libopencv_stitching.so
usr/lib/libopencv_gpu.so.2.4           usr/lib/libopencv_stitching.so.2.4
usr/lib/libopencv_gpu.so.2.4.7         usr/lib/libopencv_stitching.so.2.4.7
usr/lib/libopencv_highgui.so           usr/lib/libopencv_superres.so
usr/lib/libopencv_highgui.so.2.4       usr/lib/libopencv_superres.so.2.4
usr/lib/libopencv_highgui.so.2.4.7     usr/lib/libopencv_superres.so.2.4.7
usr/lib/libopencv_imgproc.so           usr/lib/libopencv_video.so
usr/lib/libopencv_imgproc.so.2.4       usr/lib/libopencv_video.so.2.4
usr/lib/libopencv_imgproc.so.2.4.7     usr/lib/libopencv_video.so.2.4.7
usr/lib/libopencv_legacy.so            usr/lib/libopencv_videostab.so
usr/lib/libopencv_legacy.so.2.4        usr/lib/libopencv_videostab.so.2.4
usr/lib/libopencv_legacy.so.2.4.7      usr/lib/libopencv_videostab.so.2.4.7
andre@b22958:~/bsps/yocto/rootfs$

ps: don´t forget to flash the card with the image created at /tmp/deploy/images/imx6qsabresd/core-image-x11-imx6qsabresd.sdcard

$ sudo dd if= /build/tmp/deploy/images/imx6qsabresd/core-image-x11-imx6qsabresd.sdcard of=/dev/sdb
----------------------------------------

After those 3 steps above you should be able to find all the OpenCV headers/libraries needed by mostly of your application, but in any case you need more dev packages, you can look at: /tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/opencv/2.4.6+gitAUTOINC+1253c2101b-r0/packages-split

Now that you have the OpenCV headers/libraries we need the toolchain to build our sample application, just re-do the bitbake command now adding the "-c populate" option in the command line:

/yocto/fsl-community-bsp/build$./bitbake core-image-x11 -c populate_sdk

and then run the install script created at: /yocto/fsl-community-bsp/build/tmp/deploy/sdk to install it.

With that you will be able to see the toolchain installed at: /opt/poky

Now we are able to test our sample code, just a camera test and you can find the source code here: camera_test_sample

To build this application you need a new terminal window (all environment variables will be reset), then run the setup environment:

$ cd /opt/poky/1.5+snapshot/
$ . ./environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi

and then go to the camera_test_yocto folder and type make. The binary will be placed in the bin folder.

Once flashed your card with the Yocto image (opencv included), mount the sd card in your host computer and then copy the binary to your rootfs.

To test it, run the application with the following command:

$ DISPLAY =:0 ./camera_test



EOF !


68 comments:

  1. Hi Andre,

    Thanks for the tutorial.
    when I want to build OpenCV using "bitbake core-image-x11" (after changing the config file) I get the following error:

    NOTE: Resolving any missing task queue dependencies
    ERROR: Nothing RPROVIDES 'imgproc-dev' (but /home/mahyar/Yocto/sources/poky/meta/recipes-graphics/images/core-image-x11.bb RDEPENDS on or otherwise requires it)
    NOTE: Runtime target 'imgproc-dev' is unbuildable, removing...
    Missing or unbuildable dependency chain was: ['imgproc-dev']
    ERROR: Required build target 'core-image-x11' has no buildable providers.
    Missing or unbuildable dependency chain was: ['core-image-x11', 'imgproc-dev']

    any idea how can I solve this problem?

    ReplyDelete
  2. Hi Mahyar,

    did you get yocto using the tutorial I linked in the beginning of the post ?

    I´ll double check, but I think that the OpenCV recipes are all good on this release.

    regards,
    Andre

    ReplyDelete
  3. I found the issue:

    CORE_IMAGE_EXTRA_INSTALL += "libopencv-core-dev libopencv-highgui-dev libopencv- imgproc-dev libopencv-objdetect-dev libopencv-ml-dev"

    there is a space between "libopencv-" and "imgproc-dev"... it should be all together "libopencv-imgproc-dev"

    it will solve the issue.

    regards,
    andre

    ReplyDelete
  4. This tutorial was so helpful in learning something and getting the idea.

    ReplyDelete
  5. Hi


    Need your help....
    I am building fsl-image-gui with local.conf as

    MACHINE ??= 'imx6qsabreauto'
    DISTRO ?= 'poky'
    PACKAGE_CLASSES ?= "package_rpm"
    EXTRA_IMAGE_FEATURES = "debug-tweaks dev-pkgs"
    USER_CLASSES ?= "buildstats image-mklibs image-prelink"
    PATCHRESOLVE = "noop"
    BB_DISKMON_DIRS = "\
    STOPTASKS,${TMPDIR},1G,100K \
    STOPTASKS,${DL_DIR},1G,100K \
    STOPTASKS,${SSTATE_DIR},1G,100K \
    ABORT,${TMPDIR},100M,1K \
    ABORT,${DL_DIR},100M,1K \
    ABORT,${SSTATE_DIR},100M,1K"
    CONF_VERSION = "1"

    BB_NUMBER_THREADS = '8'
    PARALLEL_MAKE = '-j 8'

    LICENSE_FLAGS_WHITELIST = "commercial"
    DL_DIR ?= "${BSPDIR}/downloads/"
    ACCEPT_FSL_EULA = ""

    CORE_IMAGE_EXTRA_INSTALL += "gpu-viv-bin-mx6q gpu-viv-bin-mx6q-dev"
    CORE_IMAGE_EXTRA_INSTALL += "libopencv-core-dev libopencv-highgui-dev libopencv-imgproc-dev libopencv-objdetect-dev libopencv-ml-dev"



    I am getting error like
    ERROR: Task 1261 (/home/mageswaran/Yocto/freescale/fsl-community-bsp/sources/meta-openembedded/meta-oe/recipes-devtools/python/python-numpy_1.7.0.bb, do_compile) failed with exit code '1'

    ReplyDelete
    Replies
    1. did you manage to fix your issue ?

      Delete
    2. Though I didn't fix the python-numpy issue, I managed to compile OpenCV
      without python support by disabling it manually as it was not working through opencv*.bb file

      Delete
    3. I have the same problem, apparently a bunch of libraries are missing: mkl, vml, guide, atlas, lapack, ... I have other stuff that look fishy to me: I am building for a Wandboard target, but the logs are in build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/ instead of build/tmp/work/wandboard_quad-poky-linux-gnueabi

      Delete
    4. Log file:
      http://www.filedropper.com/logdocompile_1

      Delete
    5. @Mageswaran: how did you disable python support? I tried removing everything that had to do with python in sources/meta-openembedded/meta-oe/recipes-support/opencv/opencv_2.4.bb, but I am left with another error, at the very end of the build:

      make[2]: Leaving directory `/home/gauthier/freescale-fsl/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/opencv/2.4.6+gitAUTOINC+c5afaa4e8d-r0/build-arm'
      /home/gauthier/freescale-fsl/build/tmp/sysroots/x86_64-linux/usr/bin/cmake -E cmake_progress_report /home/gauthier/freescale-fsl/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/opencv/2.4.6+gitAUTOINC+c5afaa4e8d-r0/build-arm/CMakeFiles 55 56
      [ 99%] Built target opencv_perf_gpu
      make[1]: Leaving directory `/home/gauthier/freescale-fsl/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/opencv/2.4.6+gitAUTOINC+c5afaa4e8d-r0/build-arm'
      make: *** [all] Error 2
      ERROR: oe_runmake failed
      WARNING: exit code 1 from a shell command.
      ERROR: Function failed: do_compile (log file is located at /home/gauthier/freescale-fsl/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/opencv/2.4.6+gitAUTOINC+c5afaa4e8d-r0/temp/log.do_compile.23730)

      Delete
    6. Hi,
      I navigated to opencv build directory and ran cmake-gui and disabled python support and recompiled

      Delete
    7. Navigate to /home/gauthier/freescale-fsl/build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/opencv/2.4.6+gitAUTOINC+c5afaa4e8d-r0/build-arm/
      and run
      cmake-gui ../ and disable python.


      Here is entire local.conf
      --------------------------------------
      ACHINE ??= 'imx6qsabreauto'
      DISTRO ?= 'poky'
      PACKAGE_CLASSES ?= "package_rpm"
      EXTRA_IMAGE_FEATURES = "debug-tweaks dev-pkgs"
      USER_CLASSES ?= "buildstats image-mklibs image-prelink"
      PATCHRESOLVE = "noop"
      BB_DISKMON_DIRS = "\
      STOPTASKS,${TMPDIR},1G,100K \
      STOPTASKS,${DL_DIR},1G,100K \
      STOPTASKS,${SSTATE_DIR},1G,100K \
      ABORT,${TMPDIR},100M,1K \
      ABORT,${DL_DIR},100M,1K \
      ABORT,${SSTATE_DIR},100M,1K"
      CONF_VERSION = "1"

      BB_NUMBER_THREADS = '6'
      PARALLEL_MAKE = '-j 6'

      LICENSE_FLAGS_WHITELIST = "commercial"
      DL_DIR ?= "${BSPDIR}/downloads/"
      ACCEPT_FSL_EULA = ""

      CORE_IMAGE_EXTRA_INSTALL += "gpu-viv-bin-mx6q gpu-viv-bin-mx6q-dev"
      CORE_IMAGE_EXTRA_INSTALL += "libopencv-core-dev libopencv-highgui-dev libopencv-imgproc-dev libopencv-objdetect-dev libopencv-ml-dev opencv-samples openssh-sftp-server boost protobuf qt4-plugin-phonon-backend-gstreamer "

      #Gstreamer Pluins
      CORE_IMAGE_EXTRA_INSTALL += "gst-plugins-base gst-plugins-bad gst-plugins-good gst-plugins-ugly gst-plugins-base-app-dev gst-plugins-base-app"


      TOOLCHAIN_HOST_TASK_append = " nativesdk-python-subprocess"
      EXTRA_IMAGE_FEATURES = "ssh-server-openssh"

      Delete
    8. Thanks for the answer. I went to the location you mentioned, unchecked "BUILD_opencv_python", Configure, Generate gave warnings. Configure complains about numpy. A lot of warnings about "This warning is for project developers", and "Policy CMP0022".

      I searched for "python" and "numpy" in cmake-gui, I can't see anything else to deselect. The PATH and INCLUDE_DIR shouldn't matter if BUILD_opencv_python is deselected, right?

      Anything else I need to change in cmake-gui, beside "BUILD_opencv_python"?

      A side-note, the var PYTHON_NUMPY_INCLUDE_DIR in cmake-gui points to a location that does not exist on my machine (/home/gauthier/freescale-fsl/build/tmp/sysroots/imx6qsabresd/usr/lib/python2.7/site-packages/numpy/core/include), which surely explains why building numpy does not work...

      Delete
    9. Sorry in you directory run "cmake-gui ." so that it takes existing setup, where you can alter things without affecting compilation.
      I hope I disabled only python!
      No idea on warning.

      Delete
    10. Interestingly, I could build numpy and an core-image-x11 with opencv according to the blog post, with fsl-community-bsp based on poky-daisy instead of poky-dora.
      The tutorial by Daiane is not updated and still points at dora, which is why I first chose this version.
      With a clean daisy, things worked as expected!
      Thanks for the help!

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. how to disable python support....please reply

    ReplyDelete
  9. Manually disabling OpenCV features with Yocto in Freescale imx6q:
    This is when you can't disable OpenCV features through yocto
    $cd path-to/fsl-community-bsp/adasYocto/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/opencv/2.4.6+gitAUTOINC+c5afaa4e8d-r0/build-arm
    $cmake-gui .
    and disable the required features

    ReplyDelete
  10. For new comers to Yocto:
    There is a bug(might be!) in Yocto build system that it takes system include path for some libraries rather taking platform rootfs and this applies to generated meta toolchain also.

    ReplyDelete
    Replies
    1. This happens when you configure your qt creator to use Yocto sysroot and you specify library or include path starting with "/".

      Eg:
      LIBS += -L /usr/local/lib/ -> WRONG

      INSTEAD DON'T SPECIFY THE DEFAULT LOCATION!

      Delete
  11. Hello Andre,

    Following your blog, I am at the last line. Here is what I get:


    root@nitrogen6x:/usr/bin#
    root@nitrogen6x:/usr/bin# lsmod
    Module Size Used by
    mxc_v4l2_capture 21674 1
    ipu_bg_overlay_sdc 3846 1 mxc_v4l2_capture
    ipu_still 1648 1 mxc_v4l2_capture
    ipu_prp_enc 4602 1 mxc_v4l2_capture
    ipu_csi_enc 2862 1 mxc_v4l2_capture
    ipu_fg_overlay_sdc 4796 1 mxc_v4l2_capture
    vivante 947 3
    drm 139387 4 vivante
    ov5642_camera 120034 0
    camera_sensor_clock 702 1 ov5642_camera
    root@nitrogen6x:/usr/bin#
    root@nitrogen6x:/usr/bin#
    root@nitrogen6x:/usr/bin# DISPLAY=:0 ./camera_test
    ov5642_powerdown: powerdown=0, power_gp=0x6
    HIGHGUI ERROR: libv4l unable to ioctl S_FMT
    HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT


    Error creating capture
    root@nitrogen6x:/usr/bin# ov5642_powerdown: powerdown=1, power_gp=0x6

    root@nitrogen6x:/usr/bin#

    Any clue about this?

    Thank you

    ReplyDelete
    Replies
    1. Yes I have, unfortunately OpenCV doesnt work with the CSI camera, its driver is incompatible with the common v4l used by linux (in general), so, it creates the video0, opencv sees the video0 but can´t communicate with it =(

      Unfortunately I tried to hack the opencv once in order to put this camera to work, but it was going to take a lot of time and work and I reached a point that I didn´t know what else to do. I had to quit this task.

      It works only with a USB camera so far.

      regards,
      Andre

      Delete
    2. Generate YOCTO image with debug tools enabled and with CMAKE package. After that install libjpegturbo (http://blog.lemoneerlabs.com/3rdParty/Darling_BBB_30fps_DRAFT.html) and OpenCV from source code (lhttp://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/) directly from the board.

      Use this command line to configure OpenCV:
      cmake -D CMAKE_C_FLAGS="-O3 -mfpu=neon -mfloat-abi=hard -ffast-math" -D CMAKE_CXX_FLAGS="-O3 -mfpu=neon -mfloat-abi=hard -ffast-math" -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -DWITH_JPEG=ON -DBUILD_JPEG=OFF -DJPEG_INCLUDE_DIR=/opt/libjpeg-turbo/include/ -DJPEG_LIBRARY=/opt/libjpeg-turbo/lib/libjpeg.a -DWITH_V4L=ON -DWITH_OPENMP=true ..

      I do that and CSI camera works for me.

      Delete
    3. http://imxcv.blogspot.com/2014/05/onboard-camera-v4l-wrapper-for-use-with.html

      Delete
  12. Hello Andre,
    Thank you very much for really good post.
    I wonder is it possible to install the opencv on not only the x11 but the fb or dfb?

    regards,
    Yoo

    ReplyDelete
    Replies
    1. Hi Yoo, yes you can do that, actually it happens automatically when you install GTK, if you have fb installed, it will be the backend for GTK, if you install x11, then the GTK will be based on X11.

      regards,
      Andre

      Delete
    2. Thanks you
      but I tried to install as adding in local.conf file. And then bitbake fsl-image-dfb. There was error.

      here is error msg...

      ERROR: Nothing PROVIDES 'virtual/libx11' (but /home/dg410/dev/jongsu/pjt/realnavy/yocto/fsl-release-bsp/sources/meta-openembedded/meta-oe/recipes-multimedia/v4l2apps/v4l-utils_0.8.8.bb DEPENDS on or otherwise requires it)
      ERROR: libx11-diet PROVIDES virtual/libx11 but was skipped: 'x11' not in DISTRO_FEATURES
      ERROR: libx11 PROVIDES virtual/libx11 but was skipped: 'x11' not in DISTRO_FEATURES
      ERROR: nativesdk-libx11 PROVIDES virtual/libx11 but was skipped: 'x11' not in DISTRO_FEATURES
      NOTE: Runtime target 'opencv' is unbuildable, removing...
      Missing or unbuildable dependency chain was: ['opencv', 'v4l-utils', 'virtual/libx11']
      ERROR: Required build target 'fsl-image-dfb' has no buildable providers.
      Missing or unbuildable dependency chain was: ['fsl-image-dfb', 'opencv', 'v4l-utils', 'virtual/libx11']

      regards,
      Yoo

      Delete
  13. Hello Andre,
    while using Yocto, can we also install OpenCV with a package manager ?
    For example, can I use "sudo apt-get install libopencv-dev" or something equivalent ?

    Would it be possible to do that ?

    Thanks
    ssinfod

    ReplyDelete
    Replies
    1. Hi There, I am note sure, since it is not Ubuntu Based linux, in the ubuntu distribution even for arm, you can do that easily, but for Ltib and Yocto I don't think it is possible.

      regards,
      Andre

      Delete
  14. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hello Andre,

      Maybe an error message such as the following, tried to build along the sentences you came out, how can I know why this message appears to me?
      I hope you give me for help.

      ====================================================


      Summary: 2 tasks failed:
      virtual:native:/home/hunsol/fsl-community-bsp/sources/poky/meta/recipes-support/neon/neon_0.30.0.bb, do_populate_sysroot
      virtual:native:/home/hunsol/fsl-community-bsp/sources/poky/meta/recipes-devtools/qemu/qemu_1.5.0.bb, do_compile
      Summary: There was 1 WARNING message shown.
      Summary: There were 2 ERROR messages shown, returning a non-zero exit code.
      =================================

      Delete
    2. I was solved. It was a problem caused by increasing to numbers task of local.conf.
      (BB_NUMBER_THREADS = '10' , PARALLEL_MAKE = '-j 10')
      That is, it was a problem that the resulting task task must be alright for later processing during task work is gradually if to be processed first because of the increased number has ended up being treated. There seems to be related dependency pkgs some.

      Delete
  15. Hi, thanks for the nice tutorial! I followed every step and stuck on the last one:
    DISPLAY=:0 ./camera_test
    with MIPI camera, I got:
    HIGHGUI ERROR: libv4l unable to ioctl S_FMT
    HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT

    So I saw your reply about MIPI camera not working, I change to USB camera. unfortunately, it shows
    HIGHGUI ERROR: V4L: index 0 is not correct!
    so I change .c file and set index to 1, still showing ".... index 1 is not correct!"

    any clue on that?
    (btw, on my Ubuntu laptop which is also the host machine, I tried "gst-launch" with USB camera, it works. I tried the same command on the wandboard-quad with Yocto, it didn't . )

    =====================
    another quick question is, I wonder how to use VideoCapture in the program, what header file I need to add? I tried several things but nothing worked.


    Thank you very much! Your tutorial is really helpful!

    Best,
    Zoe

    ReplyDelete
  16. Hi Zoe,

    for the onboard camera you need to use the mfw_v4lsrc plugin in order to make it work, for usb camera only v4lsrc.

    now regarding the issue with the application and highgui, make sure your camera is compatible with OpenCV. As I remember there are some cameras that is not compatible.

    regards,
    Andre

    ReplyDelete
  17. Hi, I have problem with Qt and OpenCV in Yocto. I made everything by this instructions, but when I build my project in Qt Creator I get this error:

    /opt/poky/1.6.1/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/lib/libgtk-x11-2.0.so:-1: error: undefined reference to `g_type_class_adjust_private_offset'

    Have you got any ideas?

    Thank you :)

    ReplyDelete
    Replies
    1. Hi Vilem,

      unfortunately I don´t have experience with QT, maybe you can get something on the QT community.

      Delete
  18. Hi, I installed opencv following this instructions and now I would like to install gstreamer1.0-plugins-bad with opencv enabled. The local.conf is the following:
    BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"
    PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count()}"
    MACHINE ??= 'imx6qsabresd'
    DISTRO ?= 'poky'
    PACKAGE_CLASSES ?= "package_rpm"
    EXTRA_IMAGE_FEATURES = "debug-tweaks"
    USER_CLASSES ?= "buildstats image-mklibs image-prelink"
    PATCHRESOLVE = "noop"
    BB_DISKMON_DIRS = "\
    STOPTASKS,${TMPDIR},1G,100K \
    STOPTASKS,${DL_DIR},1G,100K \
    STOPTASKS,${SSTATE_DIR},1G,100K \
    ABORT,${TMPDIR},100M,1K \
    ABORT,${DL_DIR},100M,1K \
    ABORT,${SSTATE_DIR},100M,1K"
    PACKAGECONFIG_pn-qemu-native = "sdl"
    PACKAGECONFIG_pn-nativesdk-qemu = "sdl"
    ASSUME_PROVIDED += "libsdl-native"
    CONF_VERSION = "1"

    BB_NUMBER_THREADS = '4'
    PARALLEL_MAKE = '-j 4'

    DL_DIR ?= "${BSPDIR}/downloads/"
    ACCEPT_FSL_EULA = "1"

    LICENSE_FLAGS_WHITELIST = "commercial"

    #Gstreeamer
    CORE_IMAGE_EXTRA_INSTALL += "gstreamer1.0 gstreamer1.0-libav gstreamer1.0-omx gstreamer1.0-plugins-bad-meta gstreamer1.0-plugins-base-meta gstreamer1.0-plugins-good-meta gstreamer1.0-plugins-ugly-meta gstreamer1.0-plugins-imx-meta"

    CORE_IMAGE_EXTRA_INSTALL += "gpu-viv-bin-mx6q gpu-viv-bin-mx6q-dev v4l-utils"
    #Opencv
    CORE_IMAGE_EXTRA_INSTALL += "opencv libopencv-core-dev libopencv-highgui-dev libopencv-imgproc-dev libopencv-objdetect-dev libopencv-ml-dev"



    PACKAGECONFIG_pn_gstreamer1.0-plugins-ugly += "x264"

    EXTRA_IMAGE_FEATURES += "tools-sdk"
    EXTRA_IMAGE_FEATURES += "ssh-server-openssh dev-pkgs"

    running bitbake core-image-base I can create a rootfs with opencv and all gstreamer plugins that I need but I can not see the opencv plugin in gstreamer bad. In other words when I run gst-inspect-1.0 | grep opencv I get anything. Haw can I do to add the opencv plugin for gstreamer?
    Thanks

    ReplyDelete
    Replies
    1. Sorry but I am not aware on how to do that, I found the same question you made here: http://stackoverflow.com/questions/24660136/is-there-an-opencv-version-which-links-against-gstreamer-1-0

      not sure if it is you. Hope it helps.

      Delete
  19. Hi Andre, Thanks for a great post.

    What's the performance you're seeing with openCV on i.mx6q? Does openCV take advantage of the graphics hardware on the i.mx6q, or does it just run on the cpu?

    Thanks again

    ReplyDelete
    Replies
    1. Hi Orion,

      unfortunately it doesnt take any advantage of the gpu. OpenCV deals with CUDA and Full profile OpenCL, imx6 only supports the embedded profile. The performance is good as long you don´t use large images, I could run the face detection demo (modified to only detected front faces), on a 320x240 image at about 30fps, if I am not wrong.

      Delete
  20. Hi and thanks for your post,

    I have one additional question, because I think your manual lacks in the same way.
    My library content regarding opencv looks the same as yours but I cant find libopencv_ts.
    It is build as a static library by opencv, but "libopencv-ts", "libopencv-ts-dev" or "libopencv-ts-staticdev" are not available.
    If I add "opencv-dev" and "opencv-staticdev", the "libopencv_ts.a" library is deployed in the image it self (which makes no sense), but not in the sdk.
    Do you know, how to get the "libopencv_ts.a" into the sdk?

    Kind regards,
    Timo

    ReplyDelete
    Replies
    1. Hi Timo, sorry for this late response, there are a lot of questions on this post and I got lost =(.

      I didn´t face this issue, I didn´t use any static library from OpenCV.

      The tip I can give you is after you bitbake using the new option you mentioned you need to extract and deploy the SDK again, it doesn´t update automaticaly (only the image) you need to do it manually.

      regards,
      Andre

      Delete
  21. Hi Andre Silva,

    I'm trying to execute the camera_test but got this output:


    ./camera_test: error while loading shared libraries: libfreenect.so.0.2: cannot open shared object file: No such file or directory

    Can you give me a clue of what might cause this error ?

    Thanks in advance,

    Pedro X. Matos

    ReplyDelete
    Replies
    1. I have the same issue, libfreenect doesn't exist, did you figure out how to add this? it appears the library is used for kinect, why is this necessary?

      Delete
    2. Hi Guys,

      maybe I didn't cleaned the makefile for this sample, sorry for that. Libfreenect is only needed for the Kinect sample post, so please, remove it from the makefile and everything should run fine.

      cheers,
      Andre

      Delete
    3. yeah, that is it, you can remove these two libraries: -lusb-1.0 -lfreenect \

      Delete
  22. I use, L3.10.53_1.1.0, .sdcard image. Do I need to configure. I am not able to build image. So, I use available image. How to make changes in that.

    ReplyDelete
    Replies
    1. I recommend you installing the sdk, it will create a rootfs with everything you need. To do that you need to use bitbake command like: bitbake core-image-x11 -c populate_sdk, after building, you can burn again the .sdcard image and you will get it working. Let me know if you have any issue then I can help you step by step.

      cheers.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. I have install. what is next step...

      Delete
  23. Hi,
    Thank you for this tutorial.
    I was wondering: how hard would it be to move to OpenCV 3.0.X with this?
    Do we need to modify the OpenCV recipe to checkout on a 3.0.X branch?
    regards,
    Alex

    ReplyDelete
  24. Hi

    I am try to install Opencv3 for sabrelite board.
    Download recipe file from 
    http://cgit.openembedded.org/cgit.cgi/meta-ope
    nembedded/tree/meta-oe/recipes-support/opencv/opencv_3.0.bb?h=master and
    remove all opencv2.4 recipe files.
    did the bitbake opencv without any problem.
    Then add following entries to local.conf and try to make core-image-x11
    using bitbake core-image-x11 command.

    CORE_IMAGE_EXTRA_INSTALL += "opencv"

    Then i got following error

    ERROR: Unable to install packages. Command '~/fsl-release-bsp/build/tmp/sysroots/x86_64-linux/usr/bin/apt-get
    install --force-yes --allow-unauthenticated psplash
    packagegroup-core-x11-base apt opencv packagegroup-core-boot
    packagegroup-base-extended dpkg' returned 100:
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    opencv : Depends: opencv-java but it is not installable
    packagegroup-core-x11-base : Depends: packagegroup-core-x11-utils but it is not going to be installed
    W: Unable to read ~/fsl-release-bsp/build/tmp/work/imx6qsabrelite-poky-linux-gnueabi/core-image-x11/1.0-r0/apt/preferences.d/
    - DirectoryExists (2: No such file or directory)
    E: Unable to correct problems, you have held broken packages.

    ERROR: Function failed: do_rootfs
    ERROR: Logfile of failure stored in: ~/fsl-release-bsp/build/tmp/work/imx6qsabrelite-poky-linux-gnueabi/core-image-x11/1.0-r0/temp/log.do_rootfs.31648
    ERROR: Task 7 (~/fsl-release-bsp/sources/poky/meta/recipes-graphics/images/core-image-x11.bb,
    do_rootfs) failed with exit code '1'


    seems that opencv-java package cannot install to core-image-x11 image.

    What was the missing part of this process and
    Did anybody was able to use OpenCV3 in Yocto ?

    Thanks in advance

    ReplyDelete
    Replies
    1. Sorry, I didn't tested OpenCV 3.x yet. Only 2.4.x which is in the Yocto's default recipe.

      regards,
      Andre

      Delete
  25. Is there any one tested OpenCV 3.x in the yocto environment.

    ReplyDelete
    Replies
    1. Hi Hasitha,

      not yet. Even on windows I got some issues with 3.x release. I am still using 2.4.x.

      regards,
      Andre

      Delete
    2. How to run programs after installing OpenCV using above procedure..I have python or C++ file...Please, I am new..explain in detail

      Delete
  26. ERROR: Nothing RPROVIDES 'gpu-viv-bin-mx6q' (but /home/swapnil/fsl-release-bsp/sources/meta-fsl-bsp-release/imx/meta-sdk/recipes-fsl/images/fsl-image-qt5.bb RDEPENDS on or otherwise requires it)
    NOTE: Runtime target 'gpu-viv-bin-mx6q' is unbuildable, removing...
    Missing or unbuildable dependency chain was: ['gpu-viv-bin-mx6q']
    ERROR: Required build target 'fsl-image-qt5' has no buildable providers.
    Missing or unbuildable dependency chain was: ['fsl-image-qt5', 'gpu-viv-bin-mx6q']

    How to remove this ..ERROR

    ReplyDelete
  27. I have install toolchain, but ,when I go inside folder & type make, it gives following error:
    make -f Makefile distclean; \
    make -f Makefile install;
    make[1]: Entering directory `/home/rahul/fQ/opencv-camera-test---i.MX6-Yocto-master/src'
    rm -rf ../src/camera_test.o
    rm -rf ../bin/camera_test.o
    rm -rf ../bin/*~ ../bin/*.core
    rm -rf ../bin/camera_test
    rm -rf ../bin/camera_test
    make[1]: Leaving directory `/home/rahul/fQ/opencv-camera-test---i.MX6-Yocto-master/src'
    make[1]: Entering directory `/home/rahul/fQ/opencv-camera-test---i.MX6-Yocto-master/src'
    arm-poky-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi -DLINUX -DUSE_SOC_MX6 -Wall -O2 -fsigned-char -march=armv7-a -mfpu=neon -mfloat-abi=hard -DEGL_API_FB -DGPU_TYPE_VIV -DGL_GLEXT_PROTOTYPES -DENABLE_GPU_RENDER_20 -I. -I/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include -I/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/glib-2.0 -I/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/lib/glib-2.0/include -I/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/libxml2 -c -o camera_test.o camera_test.c
    camera_test.c:12:37: fatal error: libfreenect/libfreenect.h: No such file or directory
    #include "libfreenect/libfreenect.h"
    ^
    compilation terminated.
    make[1]: *** [camera_test.o] Error 1
    make[1]: Leaving directory `/home/rahul/fQ/opencv-camera-test---i.MX6-Yocto-master/src'
    make: *** [camera_test] Error 2

    ReplyDelete
  28. ERROR: Nothing RPROVIDES 'gpu-viv-bin-mx6q' (but /opt/fsl-community-bsp/sources/poky/meta/recipes-graphics/images/core-image-x11.bb RDEPENDS on or otherwise requires it)
    NOTE: Runtime target 'gpu-viv-bin-mx6q' is unbuildable, removing...
    Missing or unbuildable dependency chain was: ['gpu-viv-bin-mx6q']
    ERROR: Required build target 'core-image-x11' has no buildable providers.
    Missing or unbuildable dependency chain was: ['core-image-x11', 'gpu-viv-bin-mx6q']

    please help to resolve this issue

    ReplyDelete
    Replies
    1. you can remove this package from the local.conf, just let the opencv's package.

      Delete
  29. is this required for opencv. what is the significance of this package. I have removed this from local.conf and its working. My board is phtech imx6. will it be ok to remove this from loca.cnf for this board. please help

    ReplyDelete
  30. i am trying to build OpenCV on Yocto my local.conf looks like :

    BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"
    PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count()}"
    MACHINE ??= 'imx6slzbha'
    DISTRO ?= 'poky'
    PACKAGE_CLASSES ?= "package_rpm"
    EXTRA_IMAGE_FEATURES = "debug-tweaks"
    USER_CLASSES ?= "buildstats image-mklibs image-prelink"
    PATCHRESOLVE = "noop"
    BB_DISKMON_DIRS = "\
    STOPTASKS,${TMPDIR},1G,100K \
    STOPTASKS,${DL_DIR},1G,100K \
    STOPTASKS,${SSTATE_DIR},1G,100K \
    ABORT,${TMPDIR},100M,1K \
    ABORT,${DL_DIR},100M,1K \
    ABORT,${SSTATE_DIR},100M,1K"
    PACKAGECONFIG_pn-qemu-native = "sdl"
    PACKAGECONFIG_pn-nativesdk-qemu = "sdl"
    ASSUME_PROVIDED += "libsdl-native"
    CONF_VERSION = "1"

    BB_NUMBER_THREADS = '32'
    PARALLEL_MAKE = '-j 32'

    DL_DIR ?= "${BSPDIR}/downloads/"
    ACCEPT_FSL_EULA = ""

    CORE_IMAGE_EXTRA_INSTALL += "python-core"
    CORE_IMAGE_EXTRA_INSTALL += "gpu-viv-bin-mx6q gpu-viv-bin-mx6q-dev"
    CORE_IMAGE_EXTRA_INSTALL += "libopencv-core-dev libopencv-highgui-dev \
    libopencv-imgproc-dev libopencv-objdetect-dev \
    libopencv-ml-dev"
    LICENSE_FLAGS_WHITELIST = "commercial"

    But i am facing an error :

    ERROR: Unable to install packages. Command '/media/verizon/MyBook/Brillo/stct_iog1/source/yocto/build/tmp/sysroots/x86_64-linux/usr/bin/smart --data-dir=/media/verizon/MyBook/Brillo/stct_iog1/source/yocto/build/tmp/work/imx6slzbha-poky-linux-gnueabi/core-image-minimal/1.0-r0/rootfs/var/lib/smart install -y dosfstools@cortexa9hf_vfp_neon gpu-viv-bin-mx6q@cortexa9hf_vfp_neon_mx6 uim@cortexa9hf_vfp_neon curl@cortexa9hf_vfp_neon gpu-viv-bin-mx6q-dev@cortexa9hf_vfp_neon_mx6 libopencv-ml-dev@cortexa9hf_vfp_neon kernel-modules@imx6slzbha libopencv-imgproc-dev@cortexa9hf_vfp_neon sqlite3@cortexa9hf_vfp_neon packagegroup-core-boot@imx6slzbha inetutils@cortexa9hf_vfp_neon inetutils-telnetd@cortexa9hf_vfp_neon libevent@cortexa9hf_vfp_neon avahi@cortexa9hf_vfp_neon wpa-supplicant@cortexa9hf_vfp_neon run-postinsts@all libopencv-highgui-dev@cortexa9hf_vfp_neon ti-compat-wireless-wlconf@cortexa9hf_vfp_neon ti-compat-wl18xx@imx6slzbha bluez4@cortexa9hf_vfp_neon libopencv-objdetect-dev@cortexa9hf_vfp_neon bt-firmware@imx6slzbha libopencv-core-dev@cortexa9hf_vfp_neon ti-wl18xx-firmware@cortexa9hf_vfp_neon' returned 1:

    Committing transaction...
    Preparing... ######################################## [ 0%]
    error: file /usr/lib/libstdc++.so.6 conflicts between attempted installs of libstdc++6-4.8.2-r0.cortexa9hf_vfp_neon and zbha-1.0-r0.cortexa9hf_vfp_neon

    ReplyDelete
    Replies
    1. Hi,

      The build fails with the same error on command :

      bitbake core-image-minimal -c populate_sdk

      Thanks in advance.

      Regards,
      Nauman

      Delete
  31. Hi,
    I assume libopencv-core-dev has a dependency of libstdc++ >4.6 version .
    Zbha also provides the libstdc++, which arouses this conflict.
    Can you suggest me any method to avoid this conflict and build for my board imx6slzbha.

    Thanks
    Nauman

    ReplyDelete
  32. Hi, which bsp are you using (NXP or Community) ? how you include the zbha ? let me know your steps and I can have a look on my side.

    cheers,
    andre

    ReplyDelete