Results 1 to 4 of 4

Thread: Fastest way to display a BGR image from OpenCV

  1. #1
    Join Date
    Apr 2018
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Fastest way to display a BGR image from OpenCV

    I'm writing an app that requires fairly fast updates to an image display that originates in OpenCV.

    Of course the first problem is OpenCV's unfortunate choice of BGR format. I'm dealing with that via:
    cvtColor(mat_in, mat_out, CV_BGR2RGB);
    Then creating a QImage via:
    QImage qImage(mat_out.data, mat_out.cols, mat_out.rows, mat_out.step,
    QImage::Format_RGB888);
    And finally writing a QPixMap so I can display it:
    QPixmap pixMap = QPixmap::fromImage(qImage);

    This seems very obscure, and I have no idea what Qt is doing internally, so it's tough to gauge whether performance can be optimized here.
    Given the prevalence of OpenCV, I presume that this is an often-solved problem. Can the process above be improved?

    Second problem: Most refs on Qt recommend using a QLabel for displaying the image. It works, but doesn't Qt have any widgets that are specifically optimized for image display? I'm ending up with a lot of extraneous code for doing scrolling, zoom, etc. You'd think there would be a pre-existing widget that already has those provisions. I'd settle for a custom library, if that exists.

    Any suggestions appreciated.

  2. #2
    Join Date
    Apr 2018
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Fastest way to display a BGR image from OpenCV

    Quote Originally Posted by Stringtheory View Post
    I'm writing an app that requires fairly fast updates to an image display that originates in OpenCV.

    Of course the first problem is OpenCV's unfortunate choice of BGR format. I'm dealing with that via:
    cvtColor(mat_in, mat_out, CV_BGR2RGB);
    Then creating a QImage via:
    QImage qImage(mat_out.data, mat_out.cols, mat_out.rows, mat_out.step,
    QImage::Format_RGB888);
    And finally writing a QPixMap so I can display it:
    QPixmap pixMap = QPixmap::fromImage(qImage);

    This seems very obscure, and I have no idea what Qt is doing internally, so it's tough to gauge whether performance can be optimized here.
    Given the prevalence of OpenCV, I presume that this is an often-solved problem. Can the process above be improved?

    Second problem: Most refs on Qt recommend using a QLabel for displaying the image. It works, but doesn't Qt have any widgets that are specifically optimized for image display? I'm ending up with a lot of extraneous code for doing scrolling, zoom, etc. You'd think there would be a pre-existing widget that already has those provisions. I'd settle for a custom library, if that exists.

    Any suggestions appreciated.
    No replies? Is there a better forum for this type of question, perhaps?

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fastest way to display a BGR image from OpenCV

    I suggest you to start using QGraphicsView. The QGraphicsPixmapItem is what you need.
    Òscar Llarch i Galán

  4. The following user says thank you to ^NyAw^ for this useful post:

    Stringtheory (14th April 2018)

  5. #4
    Join Date
    Apr 2018
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Fastest way to display a BGR image from OpenCV

    Thanks, NyAw. I have found a pretty good chapter that covers this in Tazehkandi's book "Computer Vision with OpenCV 3 and Qt5."
    Now that I've seen more detail, I'm wondering why QLabels are used so much for displaying images.

Similar Threads

  1. efficient way to display opencv image into Qt
    By gerardpuducul in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2016, 08:59
  2. Replies: 1
    Last Post: 18th October 2015, 12:06
  3. Replies: 7
    Last Post: 31st January 2012, 15:19
  4. Replies: 8
    Last Post: 18th March 2011, 11:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.