# Problem with encodeStructuredAppend function

**URL:** <https://forum.opencv.org/t/problem-with-encodestructuredappend-function/9417>\
**Category:** C++\
**Tags:** objdetect, qrcode\
**Created:** [July 6, 2022, 2:00pm UTC](https://forum.opencv.org/t/problem-with-encodestructuredappend-function/9417 "2022-07-06T14:00:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cecile](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cecile](https://forum.opencv.org/u/cecile)\
**Post date:** [July 6, 2022, 2:00pm UTC](https://forum.opencv.org/t/problem-with-encodestructuredappend-function/9417/1 "2022-07-06T14:00:31Z")

</div>

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 :

```auto
#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 ?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 7, 2022, 8:25am UTC](https://forum.opencv.org/t/problem-with-encodestructuredappend-function/9417/2 "2022-07-07T08:25:59Z")

</div>

> [@cecile](#):
>
> it generates only one QRcode with only the end of the string minus one.

quick look at the src makes me think, it’s a bug ([please report](https://github.com/opencv/opencv/issues/new/choose) !).

> <https://github.com/opencv/opencv/blob/4.x/modules/objdetect/src/qrcode_encoder.cpp#L352>

it shouldnt clear the `final_qrcodes` _inside_ the loop, but _before_ that  
(not sure about the `payload`, probably same problem)
