Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Conversion from QVideoFrame to Opencv

    Mobile and Embedded
    3
    10
    2837
    Loading More Posts
    • 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
      FVKamlesh last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • F
          FVKamlesh last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • F
              FVKamlesh @SGaist last edited by

              @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 Reply Quote 0
              • F
                FVKamlesh @FVKamlesh last edited by

                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 Reply Quote 0
                • Pablo J. Rogina
                  Pablo J. Rogina last edited by

                  @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 Reply Quote 0
                  • F
                    FVKamlesh @Pablo J. Rogina last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      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 Reply Quote 0
                      • F
                        FVKamlesh last edited by

                        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 Reply Quote 0
                        • First post
                          Last post