Skip to content

QR code (encoding process)#17889

Merged
alalek merged 6 commits intoopencv:3.4from
ZhengQiushi:my_3.4
Nov 15, 2021
Merged

QR code (encoding process)#17889
alalek merged 6 commits intoopencv:3.4from
ZhengQiushi:my_3.4

Conversation

@ZhengQiushi
Copy link
Copy Markdown
Contributor

@ZhengQiushi ZhengQiushi commented Jul 20, 2020

@ZhengQiushi ZhengQiushi changed the title WIP:complete the process of correcting the blocks WIP:QR code (decoding process) Jul 29, 2020
@ZhengQiushi
Copy link
Copy Markdown
Contributor Author

ZhengQiushi commented Jul 30, 2020 via email

version_index = -1;
/**find the version according to the number of data codewords*/
for( i = version_begin ; i < version_end ; i++ ){
const BlockParams * tmp_ecc_params = &(version_info_database[i].ecc[ecc_level]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you really need pointer in this case?
It is good way if you avoid pointers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pointers maybe take less space and can be used in a faster way, (although may be not that safe..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use shared pointers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that I can't 'make' normally when I use "share_ptr".It says " error: ‘shared_ptr’ in namespace ‘std’ does not name a template type
std::shared_ptr version_info ;
"
So what should I do now ? Looking forword to your help!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/truth/github/opencv/modules/objdetect/src/qrcode.cpp:2290:10: error: ‘shared_ptr’ in namespace ‘std’ does not name a template type
std::shared_ptr version_info ;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try smart pointers in opencv (here)

@ZhengQiushi
Copy link
Copy Markdown
Contributor Author

ZhengQiushi commented Oct 3, 2020 via email

@asmorkalov
Copy link
Copy Markdown
Contributor

@ZhengQiushi Do you have any progress with the patch? The PR still does not pass CI checks.

@rayonnant14
Copy link
Copy Markdown
Contributor

@ZhengQiushi Do you have any progress with the patch? The PR still does not pass CI checks.

Hi, @asmorkalov. At the moment, I and @APrigarina are working on this PR. Some QR codes modes don't work correctly, we are trying to fix it

@asenyaev
Copy link
Copy Markdown
Contributor

asenyaev commented Apr 8, 2021

jenkins cn please retry a build

@APrigarina APrigarina force-pushed the my_3.4 branch 2 times, most recently from f55c4bb to d650c14 Compare May 6, 2021 13:25
@APrigarina
Copy link
Copy Markdown
Contributor

@allnes, @rayonnant14 please review

Comment on lines +1156 to +1158
fnc1_first = false;
fnc1_second = false;
fnc1_second_AI = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are not used

std::string counter = decToBin(str_len, bits);
loadString(counter, output, true);
int i;
for (i = 0; i < str_len; i += 2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (i = 0; i < str_len; i += 2)
for (i = 0; i < str_len - 1; i += 2)

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@APrigarina Thank you for update!

Could you please add links/information somewhere about used format specification?

Comment on lines +705 to +706
int version = 0, int correction_level = CORRECT_LEVEL_L,
int mode = QR_MODE_AUTO, int structure_number = 1,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters should be split on 2 parts:

  • properties of algorithm - should go into constructor/create() methods
  • sample processing properties (output_size)

This is useful to unify algorithms and provide one interface.

@param structure_number The optional number of QR codes to generate in Structured Append mode.
@param output_size The optional size of generated QR code (by default is small and depends on version).
*/
CV_WRAP bool generate(String input, OutputArray output,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate => encode

remove unnecessary double spaces.


#include "precomp.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/calib3d.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need calib3d?

#include "precomp.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/calib3d.hpp"
#include <iostream>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iostream

should not be used in OpenCV modules.
Use logging instead.
Or properly target headers, like sstream.

Comment on lines +25 to +33
std::string decToBin(const int &format, const int &total);
int eccLevelToCode(int level);
uint8_t gfPow(uint8_t x, int power);
uint8_t gfMul(const uint8_t& x, const uint8_t& y);
Mat gfPolyMul(const Mat& p, const Mat& q);
Mat gfPolyDiv(const Mat& dividend, const Mat& divisor, const int& ecc_num);
Mat polyGenerator(const int& n);
int getBits(const int& bits, const vector<uint8_t>& payload ,int& pay_index);
void loadString(const std::string& str, vector<uint8_t>& cur_str, bool is_bit_stream);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static to make them local

QRCodeEncoder::QRCodeEncoder() : p(new Impl) {}
QRCodeEncoder::~QRCodeEncoder() {}

bool QRCodeEncoder::generate(cv::String input, cv::OutputArray output,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool result is not informative from the user perspective.

How to troubleshot the false result?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cv::

should be removed.

return; // done
}
}
std::cerr
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FAIL() <<

QRCodeEncoder encoder;
Mat result ;
bool success = encoder.generate(original_info, result);
ASSERT_TRUE(success) << "Can't generate qr image :" << name_test_image;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<< name_test_image

not necessary as this is a test parameter.

Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;

bool eq = countDiffPixels(result, src) == 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NORM_L1 or _INF

std::string image_path = findDataFile(root +"/"+ encode_qrcode_images_name[i]);

/**read from test set*/
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

straight_barcode

Avoid multiple declarations on the single line (allowed for simple cases without initialization only).
Must be defined near its usage.

@APrigarina
Copy link
Copy Markdown
Contributor

@APrigarina Thank you for update!

Could you please add links/information somewhere about used format specification?

Sure, here is ISO standard and wiki useful information

@APrigarina
Copy link
Copy Markdown
Contributor

@alalek Please review

@param encoded_info Input string to encode.
@param qrcode Generated QR code.
*/
CV_WRAP virtual void encode(String encoded_info, OutputArray qrcode) = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String

"const reference"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const String& should be used for input parameters.

here and below

output_bits.insert(output_bits.end(), bin_number.begin(), bin_number.end());
}

static int eccLevelToCode(int level)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int => QRCodeCorrectionLevel

size_t mode_count = static_cast<size_t>(mode_list.size());
ASSERT_GT(mode_count, 0u) << "Can't find validation data entries in 'test_images': " << dataset_config;

int modes[] = {1, 2, 4};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic numbers or QREncodeMode?

CV_WRAP Params();
CV_PROP_RW int version;
CV_PROP_RW int correction_level;
CV_PROP_RW int mode;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int correction_level
int mode

Can we use enums here?

const Size fixed_size = Size(200, 200);
const float border_width = 2.0;

int establishCapacity(int mode, int version, int capacity)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int mode

Please use enum type

EncodingMethods result = strategy[strategy.size() - 1];
for (size_t i = 0; i < result.blocks.size(); i++)
{
AutoEncodePerBlock result_block = result.blocks[i];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EncodingMethods result
AutoEncodePerBlock result_block

reference or const reference

for (size_t j = 0; j < str_len; j++)
{
previous = strategy[j];
std::string sub_string = cur_string.substr(j, str_len - j);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.substr(j, str_len - j)

The second argument is not needed here: https://en.cppreference.com/w/cpp/string/basic_string/substr

Comment on lines +705 to +710
EncodingMethods previous;
EncodingMethods new_method;
new_method.len = ERROR_MODE_OCCUR;
for (size_t j = 0; j < str_len; j++)
{
previous = strategy[j];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EncodingMethods previous;

Not used outside of for body, so it should be declated inside.

}
else
{
size_t str_len = cur_string.length();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cur_string.length() should be equal to i.

Comment on lines +691 to +693
enum ECIEncodings {
ECI_UTF8 = 26
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used?

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

ecc_level = parameters.correction_level;
mode_type = parameters.mode;
struct_num = parameters.structure_number;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not all variables are initialized in ctor:

    int version_size;
    int mask_type;
    uint32_t eci_assignment_number;
    uint8_t parity;
    uint8_t sequence_num;
    uint8_t total_num;

@param encoded_info Input string to encode.
@param qrcode Generated QR code.
*/
CV_WRAP virtual void encode(String encoded_info, OutputArray qrcode) = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const String& should be used for input parameters.

here and below

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@APrigarina Great job!

@alalek alalek merged commit 3e51448 into opencv:3.4 Nov 15, 2021
This was referenced Nov 20, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
@dkurt dkurt mentioned this pull request Sep 6, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants