Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Conversion from QVideoFrame to Opencv

Conversion from QVideoFrame to Opencv

Scheduled Pinned Locked Moved Solved Mobile and Embedded
10 Posts 3 Posters 3.5k Views
  • 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.
  • F Offline
    F Offline
    FVKamlesh
    wrote on last edited by
    #1

    Hi all
    I am facing issue in converting qvideoframe to opencv format. The pixelFormat() for the videoframe is "Format_YUV420p".
    The piece of code where I do the conversion is shared below
    [CODE]

    cv::Mat result(frame.height(), frame.width(), CV_8UC3,(uchar*)frame.bits());
    cv::Mat tmp;
    cvtColor(result, tmp, cv::COLOR_YUV2GRAY_I420);
    return tmp;

    [/CODE]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That's a bit light on information.
      What image are you expecting ?
      What image are you getting ?
      What version of Qt are you using ?
      What version of OpenCV are you using ?
      What platform are you running your code on ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        FVKamlesh
        wrote on last edited by
        #3

        HI
        I am working on
        Qt5.9 , Linux Kernel 4.15.
        Opencv 3.2
        Compiler: ARM EABI5

        Currently , I am able to convert QVideoFrame to QImage using the below function
        [Code] size_t byteSize = sizeof(uchar) * 4 * vidFrame.width() * vidFrame.height();
        void data = malloc(byteSize);
        QImage
        image = new QImage((uchar*)data,vidFrame.width(), vidFrame.height(), QImage::Format_ARGB32_Premultiplied,
        m_cleanImg ,data);
        [/Code]

        The QImage needs to be converted to cv::Mat , so that my Qr Scanner can read the Image. The Qr Scanner is written using zbar and opencv and the code is shared below
        [Code]
        QVideoFrame cloneFrame(frame);
        int width = cloneFrame.width(); int height = cloneFrame.height();
        ImageScanner scanner;
        scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
        Mat grey;
        Mat iFormat(img.width(), image.height(), CV_8UC4, (void*)image.bits(),image.bytesPerLine());
        size_t byteSize = sizeof(uchar) * 4 * cloneFrame.width() * cloneFrame.height();
        void data = malloc(byteSize);
        Image image(width,height,"Y800",(uchar
        )data,width*height); //Zbar library
        int n = scanner.scan(image);
        for(Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol)
        {
        std::vector<Point> vp;
        // do something useful with results
        std::cout<<"decoded: "<<symbol->get_type_name()<<"symbol: "<<symbol->get_data()<<"\n";
        int n = symbol->get_location_size();
        for(int i=0;i<n;i++){
        vp.push_back(Point(symbol->get_location_x(i),symbol->get_location_y(i)));
        }
        RotatedRect r = minAreaRect(vp);
        Point2f pts[4];
        r.points(pts);
        for(int i=0;i<4;i++)
        {
        line(myFrame,pts[i],pts[(i+1)%4],Scalar(255,0,0),3);
        }

                  }
        

        [/Code]

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Before diving further in, may I suggest taking a look at this KDAB article using QZxing ? It might simplify your setup.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          F 1 Reply Last reply
          0
          • SGaistS SGaist

            Before diving further in, may I suggest taking a look at this KDAB article using QZxing ? It might simplify your setup.

            F Offline
            F Offline
            FVKamlesh
            wrote on last edited by
            #5

            @SGaist
            Thanks
            I have started working on the QZXing library , and will update soon in the forum with any issues

            F 1 Reply Last reply
            0
            • F FVKamlesh

              @SGaist
              Thanks
              I have started working on the QZXing library , and will update soon in the forum with any issues

              F Offline
              F Offline
              FVKamlesh
              wrote on last edited by
              #6

              I am able to integrate the QZXING library and the source code with my application. But the new issue that comes is the QVideoFrames are of YUYV type
              and there is no frame conversion provided with QZXING library.
              Can i get support as i need to convert the yuyv frames to image (png) format.

              1 Reply Last reply
              0
              • Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @FVKamlesh maybe this post is applicable to you. See the response about using Qt private API (at the risk of lost compatibility in the future)

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                F 1 Reply Last reply
                0
                • Pablo J. RoginaP Pablo J. Rogina

                  @FVKamlesh maybe this post is applicable to you. See the response about using Qt private API (at the risk of lost compatibility in the future)

                  F Offline
                  F Offline
                  FVKamlesh
                  wrote on last edited by
                  #8

                  @Pablo-J.-Rogina
                  Thanks . I will update any progress that happens

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Just in case, the conversion from YUYV is not overly complicated, you can take a look at the OpenCV implementation and apply it to your image data.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      FVKamlesh
                      wrote on last edited by
                      #10

                      Using the OpenCV library, I was able to convert YUYV format to JPG format. The QZXing filter is able to read the JPG format but performance is slow.
                      The camera takes around 20-30seconds to read the converted jpg format.

                      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