1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-27 14:23:04 +04:00

Merge pull request #24548 from dkurt:qrcode_struct_append_decode

QR codes Structured Append decoding mode #24548

### Pull Request Readiness Checklist

resolves https://github.com/opencv/opencv/issues/23245

Merge after https://github.com/opencv/opencv/pull/24299

Current proposal is to use `detectAndDecodeMulti` or `decodeMulti` for structured append mode decoding. 0-th QR code in a sequence gets a full message while the rest of codes will correspond to empty strings.

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Dmitry Kurtaev
2024-02-01 16:15:14 +03:00
committed by GitHub
parent ea94f7eba9
commit fc32903b28
5 changed files with 104 additions and 26 deletions
+14 -2
View File
@@ -342,7 +342,13 @@ int QRCodeEncoderImpl::versionAuto(const std::string& input_str)
return -1;
}
const auto tmp_version = findVersionCapacity((int)payload_tmp.size(), ecc_level, possible_version);
int nbits = static_cast<int>(payload_tmp.size());
// Extra info for structure's position, total and parity + mode of final message
if (mode_type == MODE_STRUCTURED_APPEND)
nbits += 4 + 4 + 8 + 4;
const auto tmp_version = findVersionCapacity(nbits, ecc_level, possible_version);
return tmp_version;
}
@@ -365,7 +371,7 @@ void QRCodeEncoderImpl::generateQR(const std::string &input)
auto string_itr = input.begin();
for (int i = struct_num; i > 0; --i)
{
sequence_num = (uint8_t) i;
sequence_num = (uint8_t) (struct_num - i);
size_t segment_begin = string_itr - input.begin();
size_t segment_end = (input.end() - string_itr) / i;
@@ -1356,6 +1362,7 @@ private:
void decodeByte(String& result);
void decodeECI(String& result);
void decodeKanji(String& result);
void decodeStructuredAppend(String& result);
};
QRCodeDecoder::~QRCodeDecoder()
@@ -1746,6 +1753,11 @@ void QRCodeDecoderImpl::decodeSymbols(String& result) {
decodeECI(result);
else if (currMode == QRCodeEncoder::EncodeMode::MODE_KANJI)
decodeKanji(result);
else if (currMode == QRCodeEncoder::EncodeMode::MODE_STRUCTURED_APPEND) {
sequence_num = static_cast<uint8_t>(bitstream.next(4));
total_num = static_cast<uint8_t>(1 + bitstream.next(4));
parity = static_cast<uint8_t>(bitstream.next(8));
}
else
CV_Error(Error::StsNotImplemented, format("mode %d", currMode));
}