Bonjour,

j'essaie d'impléménter zxing :

main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <stdlib.h>
#include <stdint.h>
#include <fstream>
#include <string>
#include <zxing/qrcode/QRCodeReader.h>
#include <zxing/Exception.h>
#include <zxing/common/GlobalHistogramBinarizer.h>
#include <zxing/DecodeHints.h>
#include "BufferBitmapSource.h"
 
using namespace std; 
using namespace zxing; 
using namespace zxing::qrcode;
using namespace qrviddec; 
 
int main(int argc, char ** argv)
{
	try
	{
 
 
		// A buffer containing an image. In your code, this would be an image from your camera. In this 
		// example, it's just an array containing the code for "Hello!". 
		uint8_t buffer[] = 
		{ 
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
			255,  0 , 255, 255, 255, 255, 255,  0 , 255, 255,  0 , 255,  0 , 255, 255,  0 , 255, 255, 255, 255, 255,  0 , 255, 
			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 , 255, 255, 255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 
			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 ,  0 , 255, 255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 
			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255, 255,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 
			255,  0 , 255, 255, 255, 255, 255,  0 , 255, 255, 255, 255,  0 ,  0 , 255,  0 , 255, 255, 255, 255, 255,  0 , 255, 
			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
			255, 255, 255, 255, 255, 255, 255, 255, 255,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 
			255,  0 ,  0 , 255,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 , 255,  0 , 255,  0 , 255, 255, 255, 255, 255,  0 , 255, 
			255,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255,  0 , 255, 255,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255, 255, 255, 
			255, 255, 255, 255, 255, 255, 255,  0 , 255,  0 ,  0 ,  0 , 255, 255,  0 ,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255, 
			255, 255, 255,  0 ,  0 , 255, 255, 255,  0 ,  0 ,  0 , 255,  0 , 255, 255, 255, 255, 255, 255,  0 , 255, 255, 255, 
			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255,  0 , 255, 255, 255, 255,  0 , 255, 255,  0 , 255,  0 , 255, 255, 
			255, 255, 255, 255, 255, 255, 255, 255, 255,  0 ,  0 , 255,  0 ,  0 , 255, 255, 255, 255,  0 , 255,  0 ,  0 , 255, 
			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255, 255,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 , 255, 255, 255, 
			255,  0 , 255, 255, 255, 255, 255,  0 , 255, 255,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 ,  0 ,  0 ,  0 , 255, 255, 255, 
			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255,  0 , 255, 255,  0 ,  0 , 255,  0 ,  0 , 255,  0 , 255,  0 ,  0 , 255, 
			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 
			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 , 255, 255, 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
			255,  0 , 255, 255, 255, 255, 255,  0 , 255,  0 , 255,  0 , 255, 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 , 255,  0 ,  0 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
			255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
		}; 
		int width = 23; 
		int height = 23; 
 
		// Convert the buffer to something that the library understands. 
		Ref<LuminanceSource> source (new BufferBitmapSource(width, height, buffer)); 
 
		// Turn it into a binary image. 
		Ref<Binarizer> binarizer (new GlobalHistogramBinarizer(source)); 
		Ref<BinaryBitmap> image(new BinaryBitmap(binarizer));
 
		// Tell the decoder to try as hard as possible. 
		DecodeHints hints(DecodeHints::DEFAULT_HINT); 
		hints.setTryHarder(true); 
 
		// Perform the decoding. 
    QRCodeReader reader;
    Ref<Result> result(reader.decode(image, hints));
 
		// Output the result. 
    cout << result->getText()->getText() << endl;
 
  } 
	catch (zxing::Exception& e) 
	{
    cerr << "Error: " << e.what() << endl;
  }
	return 0; 
}
BufferBitmapSource.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "BufferBitmapSource.h"
#include <iostream>
 
namespace qrviddec {
 
BufferBitmapSource::BufferBitmapSource(int inWidth, int inHeight, unsigned char * inBuffer) 
{
	width = inWidth; 
	height = inHeight; 
	buffer = inBuffer; 
}
 
BufferBitmapSource::~BufferBitmapSource()
{
}
 
int BufferBitmapSource::getWidth() const
{
	return width; 
}
 
int BufferBitmapSource::getHeight() const
{
	return height; 
}
 
unsigned char * BufferBitmapSource::getRow(int y, unsigned char * row)
{
	if (y < 0 || y >= height) 
	{
		fprintf(stderr, "ERROR, attempted to read row %d of a %d height image.\n", y, height); 
		return NULL; 
	}
	// WARNING: NO ERROR CHECKING! You will want to add some in your code. 
	if (row == NULL) row = new unsigned char[width]; 
	for (int x = 0; x < width; x ++)
	{
		row[x] = buffer[y*width+x]; 
	}
	return row; 
}
 
unsigned char * BufferBitmapSource::getMatrix()
{
	return buffer; 
}
 
}
BufferBitmapSource.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <zxing/LuminanceSource.h>
#include <stdio.h>
#include <stdlib.h>
using namespace zxing; 
namespace qrviddec {
 
class BufferBitmapSource : public LuminanceSource {
private:
  int width, height; 
  unsigned char * buffer; 
 
public:
  BufferBitmapSource(int inWidth, int inHeight, unsigned char * inBuffer); 
  ~BufferBitmapSource(); 
 
  int getWidth() const; 
  int getHeight() const; 
  unsigned char* getRow(int y, unsigned char* row); 
  unsigned char* getMatrix(); 
}; 
}
mais g++ me retourne cette erreur :

main.cpp:55: error: cannot allocate an object of abstract type 'qrviddec::BufferBitmapSource'
BufferBitmapSource.h:7: note: because the following virtual functions are pure within 'qrviddec::BufferBitmapSource':
zxing/qrcode/../LuminanceSource.h:42: note: virtual zxing::ArrayRef<char> zxing::LuminanceSource::getRow(int, zxing::ArrayRef<char>) const
zxing/qrcode/../LuminanceSource.h:43: note: virtual zxing::ArrayRef<char> zxing::LuminanceSource::getMatrix() const
BufferBitmapSource.cpp: In constructor 'qrviddec::BufferBitmapSource::BufferBitmapSource(int, int, unsigned char*)':
BufferBitmapSource.cpp:6: error: no matching function for call to 'zxing::LuminanceSource::LuminanceSource()'
zxing/LuminanceSource.h:35: note: candidates are: zxing::LuminanceSource::LuminanceSource(int, int)
zxing/LuminanceSource.h:29: note: zxing::LuminanceSource::LuminanceSource(const zxing::LuminanceSource&)
merci de votre aide