Opencv3.x issue on Apalis iMX6 under Linux BSP V2.8b5

Dear Support Team,

we are testing Opencv 3.3 function on Apalis iMX6 under latest Linux BSP v2.8b5 according to below developer articles, and met some issue making the sample code running on Apalis imx6, detailed information is as below, could you help on this?

  1. add opencv support to linux bsp v2.8b5, have tried both opkg and openembedded way as below:
    ./ opkg way

    root@apalis-imx6:~# opkg update

    root@apalis-imx6:~# opkg install opencv

    ./ openembedded way

    a. add opecv and qt support to local.conf file
    IMAGE_INSTALL_append = " opencv tslib tslib-calibrate tslib-tests qtserialbus qtserialport qtwebengine qtwebengine-dev"
    PACKAGECONFIG_append_pn-qtbase = " tslib sql-sqlite linuxfb"
    PACKAGECONFIG_append_pn-qtmultimedia = " gstreamer"
    

    b. patch the opencv_3.3.bb file as below
    — a/layers/meta-openembedded/meta-oe/recipes-support/opencv/opencv_3.3.bb 2019-03-04 16:54:14.478234788 +0800
    +++ b/layers/meta-openembedded/meta-oe/recipes-support/opencv/opencv_3.3.bb 2019-03-04 17:08:42.423893780 +0800
    @@ -78,9 +78,8 @@
    "
    EXTRA_OECMAKE_append_x86 = " -DX86=ON"

    -PACKAGECONFIG ??= "python3 eigen jpeg png tiff v4l libv4l gstreamer samples tbb gphoto2 \

    • ${@bb.utils.contains(“DISTRO_FEATURES”, “x11”, “gtk”, “”, d)} \
    • ${@bb.utils.contains(“LICENSE_FLAGS_WHITELIST”, “commercial”, “libav”, “”, d)}"
      +PACKAGECONFIG ??= "python3 eigen jpeg png tiff v4l libv4l gstreamer samples tbb gphoto2 libav \
    • ${@bb.utils.contains(“DISTRO_FEATURES”, “x11”, “gtk”, “”, d)}"

    PACKAGECONFIG[amdblas] = “-DWITH_OPENCLAMDBLAS=ON,-DWITH_OPENCLAMDBLAS=OFF,libclamdblas,”
    PACKAGECONFIG[amdfft] = “-DWITH_OPENCLAMDFFT=ON,-DWITH_OPENCLAMDFFT=OFF,libclamdfft,”
    @@ -192,3 +191,5 @@
    cp -f bin/-tutorial- bin/-example- ${D}${datadir}/OpenCV/samples/bin/
    fi
    }
    +
    +CXXFLAGS += " -Wa,-mimplicit-it=thumb"

  2. compile the sample code in the developer article with the SDK compiled from above oe configuration, the source file and make file is in the attachment.

link text
;
3. run the binary app on apalis imx6 under either official v2.8b5 image with opkg way or openembedded way image got the same issue as below:

root@apalis-imx6:~# ./facedetect 
VIDEOIO ERROR: V4L: device v4l2:///dev/video3: Unable to query number of channels
[  874.462777] usb 1-1.1.3: reset high-speed USB device number 4 using ci_hdrc
[  874.837488] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[  874.844194] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[  874.850734] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[  875.002212] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[  875.008136] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[  875.014488] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[INFO]  Product Info: i.MX6Q/D/S
display(/dev/fb0) resolution is (1920x1080).
[  875.881909] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[  875.888105] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[  875.894321] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE

(facedetect:1398): GStreamer-CRITICAL **: gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (dest)' failed
OpenCV Error: Unspecified error (GStreamer: cannot link color -> sink
) in cvCaptureFromCAM_GStreamer, file /usr/src/debug/opencv/3.3+gitAUTOINC+87c27a074d_2a9d1b22ed_a62e20676a_34e4206aef_fccf7cd6a4-r0/git/modules/video
io/src/cap_gstreamer.cpp, line 816
VIDEOIO(cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename)): raised OpenCV exception:

/usr/src/debug/opencv/3.3+gitAUTOINC+87c27a074d_2a9d1b22ed_a62e20676a_34e4206aef_fccf7cd6a4-r0/git/modules/videoio/src/cap_gstreamer.cpp:816: error: (
-2) GStreamer: cannot link color -> sink
 in function cvCaptureFromCAM_GStreamer

ERROR: Could not access the camera!

:
4. the attached usb camera is /dev/video3

root@apalis-imx6:~# v4l2-ctl --list-devices
[ 2009.637361] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[ 2009.643685] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
[ 2009.649534] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
DISP3 BG ():[ 2009.747259] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
        /dev/video16
        /dev/video17
UVC Camera (046d:081b) (usb-ci_hdrc.1-1.1.3):
        /dev/video3

Failed to open /dev/video0: Resource temporarily unavailable

Hi Jaski,

Appreciate for the help, i have fix this issue by include below patch file to opencv_3.3.bb under below OE layer position.

layers/meta-openembedded/meta-oe/recipes-support/opencv/opencv_3.3.bb

and the patch file need to be placed in the opencv folder in the same position of opencv_3.3.bb file.
0004-cap-gstreamer-cpp-fix.patch

diff --git a/modules/videoio/src/cap_gstreamer.cpp b/modules/videoio/src/cap_gstreamer.cpp

--- a/modules/videoio/src/cap_gstreamer.cpp     2019-03-05 17:23:14.221283472 +0800
+++ b/modules/videoio/src/cap_gstreamer.cpp     2019-03-07 11:30:27.061026620 +0800
@@ -82,7 +82,7 @@
 #define COLOR_ELEM "videoconvert"
 #define COLOR_ELEM_NAME COLOR_ELEM
 #else
-#define COLOR_ELEM "autovideoconvert"
+#define COLOR_ELEM "videoconvert"
 #define COLOR_ELEM_NAME COLOR_ELEM
 #endif

@@ -813,7 +813,7 @@
         {
             if(!gst_element_link(uridecodebin, color))
             {
-                CV_ERROR(CV_StsError, "GStreamer: cannot link color -> sink\n");
+                CV_ERROR(CV_StsError, "GStreamer: cannot link uridecodebin -> color\n");
                 gst_object_unref(pipeline);
                 pipeline = NULL;
                 return false;

Perfect, that it works. Thanks for the feedback.