How to Use C++/Qt/QML/OpenCV to Write Mobile Applications

I have avoided using QML for long time and always wrote even the most simple applications using Qt Widgets and C++ code but the release of Qt’s Quick Controls 2 and Material Style just made it very irresistible and I had to go for it. Well it didn’t take too long to get a hold of things (for a newcomer) since I had enough programming experience and QML is just too well-structured and easy to learn and use. In this post I’m going to share a project that demonstrates using OpenCV in QML to write beautiful and powerful Android (and other platforms) apps.

This project is already released at http://amin-ahmadi.com/quick-camera-cv and it’s a very resourceful example which contains the following lessons in it:

  • How to interact between Qt’s QML and C++ classes
  • How to use OpenCV with QML
  • How to access a system’s Camera (Android, Windows and so on) using Qt/QML
  • And many more …

Here are some screenshots of the program running on my Android Galaxy S4 (Android 5.0):

 

Please post your questions using Contact Me page or post a comment below.

8 Replies to “How to Use C++/Qt/QML/OpenCV to Write Mobile Applications”

  1. How do you display a cv::Mat image in qml image? I’ve tried QQuickImageProvider after converting the cv::Mat to QPixmap but was unsuccessful. I’m new to qml and image stuff, and I can’t really follow what you implemented.

    1. Did you check the source codes? In this example I’m actually opening the saved file but you can do it quite easily using QQuickPaintedItem as long as you know how to convert Mat to QImage. You can search my website for that too.

    1. That’s not so easy but it’s definitely possible (I for one have tried this with success 🙂 . Android usually provides an OpenGL texture for the frames. You can try drawing this texture on a widget and then use grab to get the frame:
      http://doc.qt.io/qt-5/qwidget.html#grab

      Unfortunately with this method you’ll add a huge process to the chain and drop the frame rate.

      If you are using OpenCV you can also try building OpenCV with OpenGL support for Android. And then this function:
      http://docs.opencv.org/2.4/modules/core/doc/opengl_interop.html#ogl-texture2d-copyto

      It’s way faster but it’s still not fast enough for a serious real-time task. Still, I’d give it a shot!

      If you still face issues after all this, you need to try using a higher version of Android since I noticed you are using 4.X something which is not good. Try with a device that is at least Android 5.X

      If none of these ideas help, come back and we can try some more ideas 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *