Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert QvideoFrame to Mat image
Qt 6.11 is out! See what's new in the release blog

Convert QvideoFrame to Mat image

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • giuBRITG Offline
    giuBRITG Offline
    giuBRIT
    wrote on last edited by
    #1

    Hello,
    i need to analyze a QvideoFrame in OpenCV, how do i convert the QvideoFrame into a Mat image?

    Thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      asanka424
      wrote on last edited by
      #2

      Hi
      To answer you question you will need three things,

      Image data -> can be taken from bits() (be sure to call map() function first)
      image dimensions -> call width() and height() function
      image data format -> call pixelFormat()

      Use those information to create cv::Mat

      However if you want to analyze frames from OpenCV why dont you use it to read the video in first place. Why use Qt?

      Thanks

      giuBRITG 2 Replies Last reply
      0
      • A asanka424

        Hi
        To answer you question you will need three things,

        Image data -> can be taken from bits() (be sure to call map() function first)
        image dimensions -> call width() and height() function
        image data format -> call pixelFormat()

        Use those information to create cv::Mat

        However if you want to analyze frames from OpenCV why dont you use it to read the video in first place. Why use Qt?

        Thanks

        giuBRITG Offline
        giuBRITG Offline
        giuBRIT
        wrote on last edited by
        #3

        @asanka424 I am using QT because i need a GUI.. ye..would have been way easier that way

        A 1 Reply Last reply
        0
        • giuBRITG giuBRIT

          @asanka424 I am using QT because i need a GUI.. ye..would have been way easier that way

          A Offline
          A Offline
          asanka424
          wrote on last edited by
          #4

          @giuBRIT You can still use Qt widgets with OpenCV. In a simplest way, you can update the image on QLabel as your video output. But all depend on your application requirements

          1 Reply Last reply
          0
          • A asanka424

            Hi
            To answer you question you will need three things,

            Image data -> can be taken from bits() (be sure to call map() function first)
            image dimensions -> call width() and height() function
            image data format -> call pixelFormat()

            Use those information to create cv::Mat

            However if you want to analyze frames from OpenCV why dont you use it to read the video in first place. Why use Qt?

            Thanks

            giuBRITG Offline
            giuBRITG Offline
            giuBRIT
            wrote on last edited by
            #5

            @asanka424 Could you please be more specific regarding the three things? I don't quite understnad how to call bits and map function.. would you mind posting a small example?

            A 1 Reply Last reply
            0
            • giuBRITG giuBRIT

              @asanka424 Could you please be more specific regarding the three things? I don't quite understnad how to call bits and map function.. would you mind posting a small example?

              A Offline
              A Offline
              asanka424
              wrote on last edited by
              #6

              @giuBRIT Unfortunately I dont have a sample code to share with you. But to give you more information
              Image data is bits in your image. For example if you have a video frame of 640x480 pixels which means you have 640*480 pixel data. These data will be in a byte array. How this array is formed depend on the format of your video frame. For example if this is a 8 bit grey scale image your array will have same number of bytes as your pixels. If this is a RGB (color) image each pixel will have three bytes to represent the colors of Red, Green and Blue components. Also these color components can be in a different order, for example, it cant BGR rather than RGB. Thats why you want to know the pixel format. Last the dimensions will tell you width and height of your frame.

              If you are not familiar with these things I strongly encourage you to read relevant literature and get a good idea.

              Thanks

              giuBRITG 1 Reply Last reply
              0
              • A asanka424

                @giuBRIT Unfortunately I dont have a sample code to share with you. But to give you more information
                Image data is bits in your image. For example if you have a video frame of 640x480 pixels which means you have 640*480 pixel data. These data will be in a byte array. How this array is formed depend on the format of your video frame. For example if this is a 8 bit grey scale image your array will have same number of bytes as your pixels. If this is a RGB (color) image each pixel will have three bytes to represent the colors of Red, Green and Blue components. Also these color components can be in a different order, for example, it cant BGR rather than RGB. Thats why you want to know the pixel format. Last the dimensions will tell you width and height of your frame.

                If you are not familiar with these things I strongly encourage you to read relevant literature and get a good idea.

                Thanks

                giuBRITG Offline
                giuBRITG Offline
                giuBRIT
                wrote on last edited by
                #7

                @asanka424 thanks

                I 1 Reply Last reply
                0
                • giuBRITG giuBRIT

                  @asanka424 thanks

                  I Offline
                  I Offline
                  Ivan_Rubianes
                  wrote on last edited by
                  #8
                  This post is deleted!
                  I 1 Reply Last reply
                  0
                  • I Ivan_Rubianes

                    This post is deleted!

                    I Offline
                    I Offline
                    Ivan_Rubianes
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved