How to install OpenCV for python2 on iMX6UL-EVK ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to install OpenCV for python2 on iMX6UL-EVK ?

Jump to solution
2,372 Views
toanjunifer
Senior Contributor I

Hi NXPs,

My name is Toan. Currently, I'm using iMX6UL-EVK. I did many things with it. It's so great. And now I have some trouble:
I'm using kernel 4.14.98_2.0.0. I can only install PyQt5 which running with Python 2( PyQt4 is not available). But I can not install OpenCV for python2. I can install for Python3 via edit local.conf file. 
And I wanna use opencv on python2 to combine with PyQt5. So what should I do now ?

Note: I try to install via source code with cmake but It's require Qt5 configure or anything like this. I also try with pip,

$ pip install opencv-python

Thank you so much,

Toan

Labels (1)
1 Solution
2,093 Views
toanjunifer
Senior Contributor I

Hi weidong.sun‌,

Thank you for your support. Finally, I installed OpenCV with python 2 successfully. I installed pt5-creator first and then I install opencv via source code. It's quite stupid but It's successfully and it's take a long time. I think I need to solve a new issue.

Thank you again !

Best regards,

Toan

View solution in original post

0 Kudos
Reply
6 Replies
2,093 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hello Dao Van Toan,

There are many documents in our community describing how to install opencv, such as the following link.

Setting Up OpenCV in i.MX6 Based Boards 

Building OpenCV on ubuntu hardfloat rootfs for i.MX6Q 

If you think these documents are not enough, you can search "building opencv" in the community.

Have a nice day!

BR,

Weidong

2,093 Views
toanjunifer
Senior Contributor I

Hi weidong.sun‌,

Thank you for your response. The links above may not help. Because iMX6Q can run Ubuntu and iMX6UL is not. Do you think iMX6UL-EVK can run with the ubuntu(linaro-alip) ?

Regards,
Toan

0 Kudos
Reply
2,093 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hello Dao,

   I don't know if you can access the link , which guides users to add opencv to Yocto.

https://blog.csdn.net/caibaihui/article/details/20741649 

  If you can't access it, you can see below, please!

You can refer to it, but you konw , there is no GPU in i.MX6UL, so APIs required GPU in OpenCV can not be used.

------------------------------------------------------------------------------------------------------------------------------------------------

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

Computer Vision on i.MX Processors

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/
$ . ./envionment-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
pastedImage_5.png
----------------------------------------------------------------------------------------------------------------------------------------------------
Have a nice day!
BR,
Weidong
2,094 Views
toanjunifer
Senior Contributor I

Hi weidong.sun‌,

Thank you for your support. Finally, I installed OpenCV with python 2 successfully. I installed pt5-creator first and then I install opencv via source code. It's quite stupid but It's successfully and it's take a long time. I think I need to solve a new issue.

Thank you again !

Best regards,

Toan

0 Kudos
Reply
2,093 Views
toanjunifer
Senior Contributor I

Hi weidong.sun‌,

I tried follow your link and it's not working (not compatible with python 2 and also python 3). I think the problem is kernel version. I'm using both BSP kernel version 4.14.98 and 4.9.98. Kernel 4.14.98 has opnecv 4.0.1 and kernel 4.9.98 has opencv 3.4. So I guess that if I use kernel lower, I will get opencv 2.4.7 which only compatible with python 2.

Regards,

Toan

0 Kudos
Reply
2,093 Views
toanjunifer
Senior Contributor I

Hi weidong.sun‌,

Thank you for your enthusiasm. I think this Saturday, I will don't have day-off and wrestle with this issue. It's very worth to try.

Best regards,

Toan

0 Kudos
Reply