Problem with encodeStructuredAppend function

Hello there ! I’m working with OpenCV in order to generate QRCodes.
OpenCV version => Windows openCV 4.5.5 and 4.6.0
Environment => C++ with visual studio 2022

I want to use the function encodeStructuredAppend from objdetect.hpp so I used the test test_qrcode_encode.cpp to understand this function.

The code looks like this :

#include <iostream>
#include "opencv2/opencv.hpp"
#include <opencv2/objdetect.hpp>
#include <vector>


int main()
{
    std::string input_info = "Some text to test, more or less big, i tried differents things";
    cv::QRCodeEncoder::Params params;
    params.structure_number = 3;
    params.mode = cv::QRCodeEncoder::EncodeMode::MODE_STRUCTURED_APPEND;

    cv::Ptr<cv::QRCodeEncoder> encoder = cv::QRCodeEncoder::create(params);

    std::vector<cv::Mat> qrcodes;

    encoder->encodeStructuredAppend(input_info, qrcodes);
    
    if(qrcodes.empty()) std::cout << "Can't generate this QR images";
    std::cout << qrcodes.size() << std::endl;

    for (size_t k = 0; k < qrcodes.size(); k++)
    {
        cv::Mat qrcode = qrcodes[k];
        std::string sav = "qrcode/qr" + std::to_string(k) + ".jpg";
        cv::imwrite(sav, qrcode);
        std::cout << k << std::endl;
    }
}

However, no matter what params.structure_number equal the number of QRcodes generated is one.

If I try with params.structure_number = 1 it generate only one QR with all the informations in it but if I put more than one it generates only one QRcode with only the end of the string minus one.

Did I do something wrong ?

1 Like

quick look at the src makes me think, it’s a bug (please report !).

it shouldnt clear the final_qrcodes inside the loop, but before that
(not sure about the payload, probably same problem)