Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV 2.4.4 with ZXing 2.1

Hello,

I'am trying to use ZXing with OpenCV in order to read QR code in C++ technology. I need help about this... If someone have already do that, can you tell me how please?

My first way was to integrate a class name's CVImageSource like this :

CVImageSource::CVImageSource(IplImage* image) {
    image_ = image;
    width =  image->width;
    height = image->height;
}

CVImageSource::~CVImageSource(){}

int CVImageSource::getWidth() const {
    return width;
}

int CVImageSource::getHeight() const {
  return height;
}


unsigned char* CVImageSource::getRow(int r, unsigned char* row) {

    int width = getWidth();
    if(row == NULL){
        row = new unsigned char[width];
    }

    /* Test */
    unsigned char* rowTemp = new unsigned char[width];

    rowTemp = row;
    /* fin Test */
    try{
        for(int c = 0; c < width; c++){
            CvScalar pixel = cvGet2D(&image_, r, c);

            if(image_->depth == IPL_DEPTH_8U || image_->depth == IPL_DEPTH_8S){
                //8 bits depth on each channel
                row[c] = (unsigned char) ((306 * (int)pixel.val[0] + 601 * (int)pixel.val[1] + 
                        117 * (int)pixel.val[2] + 0x200) >> 10);
            }
            else if(image_->depth == IPL_DEPTH_16S){
                //16 bits depth on each channel
                // 0x200 = 1<<9, half an lsb of the result to force rounding
                // I don't know why we do multiplication 306 - 601 - 117 for each channel... I don't find the reason... sorry
                row[c] = (unsigned char) ((306 * ((int)pixel.val[0] >> 8) + 601 * ((int)pixel.val[1] >> 8) +
                        117 * ((int)pixel.val[2] >> 8) + 0x200) >> 10);
            }

        }
    }
    catch(cv::Exception ecv){
        cout << "Error : " << ecv.what() << endl;
    }
    return row;
}

unsigned char* CVImageSource::getMatrix(){
    int width = getWidth();
    int height = getHeight();
    CvScalar pixel; 

    unsigned char* matrix = new unsigned char[width * height];
    unsigned char* m = matrix;

    for(int l = 0; l < height; l++){
        for(int c = 0; c< width; c++){
            pixel = cvGet2D(&image_, l, c);
            if(image_->depth == IPL_DEPTH_8U || image_->depth == IPL_DEPTH_8S){
                //8 bits depth on each channel
                *m = (unsigned char) ((306 * (int)pixel.val[0] + 601 * (int)pixel.val[1] + 
                    117 * (int)pixel.val[2] + 0x200) >> 10);
            }
            else if(image_->depth == IPL_DEPTH_16S){
                //16 bits depth on each channel
                // 0x200 = 1<<9, half an lsb of the result to force rounding
                // I don't know why we do multiplication 306 - 601 - 117 for each channel... I don't find the reason... sorry
                *m = (unsigned char) ((306 * ((int)pixel.val[0] >> 8) + 601 * ((int)pixel.val[1] >> 8) +
                    117 * ((int)pixel.val[2] >> 8) + 0x200) >> 10);
            }
            m++;
        }
    }
    return matrix; /* Warning m is just a pointer */
}

But when I run application using this one, I have exception as :

OpenCV Error: Bad argument (unrecognized or unsupported array type) in unknown function, file ..\..\..\src\opencv\modules\core\src\array.cpp, line 1830
What : ..\..\..\src\opencv\modules\core\src\array.cpp:1830: error: (-5) unrecognized or unsupported array type

The exception is thrown when the application come in the getRow function. It seem there's a trouble with unsigned char *row, but I don't know why...

Have you an idea guys? Thanks.