Hello,
I'm encoding a byte array into qr code using libqrencode and than try to decode it using zbar library. the programming language is c++.
The problem occurs when the values are >=128. for example when I decode the qr code which contains the following values:
I got the following result:
111, 127, 194, 128, 195, 160, 195, 191, 194, 178, 195, 137, 195, 136, 195, 128, 194, 191, 22, 17, 20, 34, 65, 23, 76,
So as we can notice the values < 128 didn't effected but I got two bytes for every value >=128. Also I printed the values without casting to unsigned char:
and the result is:
111, 127, -62, -128, -61, -96, -61, -65, -62, -78, -61, -119, -61, -120, -61, -128, -62, -65, 22, 17, 20, 34, 65, 23, 76
I solve this problem by the following code:
void process_zbar_output(const string & input_data, vector<unsigned char=""> & output_data)
{
for (int i = 0; i < input_data.length(); i++)
{
int temp = (int) input_data[i];
// if the original value is >=128 we need to process it to get the original value
if (temp < 0)
{
// if the number is 62 than the original is between 128 and 191
// if the number is 61 than the original is between 192 and 255
if (temp == -62)
output_data.push_back(256 + ((int) input_data[i + 1]));
else
output_data.push_back(256 + ((int) input_data[i + 1] + 64));
i++;
}
else
{
output_data.push_back( input_data[i]);
}
}
}
Can anybody help me with this problem and explain why I got these extra bytes?
notice: the decoded values are (194, 128 when casting to uchar) or (-62, -128 without casting to uchar) instead of 128. So I used the values (-62, -128) in my function "process_zbar_output" to get the original value. Moreover I can get the original values in range [128..191] from the second component (194, 128) and it is true for all values in this range. But that isn't true for values in range [192..255].
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
libZbar not support reading raw data. It return decoded data as text in UTF-8.
If code contain binary data, library suppose than it is text in ISO 8859-1 code page and convert it to utf-8.
Same question discussed many times in this forum, but project seems not supported.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I'm encoding a byte array into qr code using libqrencode and than try to decode it using zbar library. the programming language is c++.
The problem occurs when the values are >=128. for example when I decode the qr code which contains the following values:
unsigned char data[17]={111, 127, 128, 224, 255, 178, 201,200, 192, 191,22, 17,20, 34, 65 ,23, 76};
symbol->get_data_length() return 25 instead of 17 and when I tried to print the values using this small piece of code:
string input_data = symbol->get_data();
for(int k=0; k< 25; k++)
cout<< (int)((unsigned char)input_data[k])<<", ";
I got the following result:
111, 127, 194, 128, 195, 160, 195, 191, 194, 178, 195, 137, 195, 136, 195, 128, 194, 191, 22, 17, 20, 34, 65, 23, 76,
So as we can notice the values < 128 didn't effected but I got two bytes for every value >=128. Also I printed the values without casting to unsigned char:
for(int k=0; k< 25; k++)
cout<< (int)input_data[k]<<", ";
and the result is:
111, 127, -62, -128, -61, -96, -61, -65, -62, -78, -61, -119, -61, -120, -61, -128, -62, -65, 22, 17, 20, 34, 65, 23, 76
I solve this problem by the following code:
void process_zbar_output(const string & input_data, vector<unsigned char=""> & output_data)
{
for (int i = 0; i < input_data.length(); i++)
{
int temp = (int) input_data[i];
// if the original value is >=128 we need to process it to get the original value
if (temp < 0)
{
// if the number is 62 than the original is between 128 and 191
// if the number is 61 than the original is between 192 and 255
if (temp == -62)
output_data.push_back(256 + ((int) input_data[i + 1]));
else
output_data.push_back(256 + ((int) input_data[i + 1] + 64));
i++;
}
else
{
output_data.push_back( input_data[i]);
}
}
}
Can anybody help me with this problem and explain why I got these extra bytes?
notice: the decoded values are (194, 128 when casting to uchar) or (-62, -128 without casting to uchar) instead of 128. So I used the values (-62, -128) in my function "process_zbar_output" to get the original value. Moreover I can get the original values in range [128..191] from the second component (194, 128) and it is true for all values in this range. But that isn't true for values in range [192..255].
Hello.
libZbar not support reading raw data. It return decoded data as text in UTF-8.
If code contain binary data, library suppose than it is text in ISO 8859-1 code page and convert it to utf-8.
Same question discussed many times in this forum, but project seems not supported.