refactoring in qzxing.cpp to remove uneeded references

This commit is contained in:
favoritas37 2016-03-18 21:01:48 +02:00
parent 3798e89fb6
commit 00d0e8d8d0
9 changed files with 193 additions and 221 deletions

View File

@ -157,45 +157,6 @@ ArrayRef<char> CameraImageWrapper::getMatrixP() const
return arr;
}
QImage *CameraImageWrapper::sharpen(const QImage *origin)
{
QImage * newImage = new QImage(* origin);
int kernel [3][3]= {{0,-1,0},
{-1,5,-1},
{0,-1,0}};
int kernelSize = 3;
int sumKernel = 1;
int r,g,b;
QColor color;
for(int x=kernelSize/2; x<newImage->width()-(kernelSize/2); x++){
for(int y=kernelSize/2; y<newImage->height()-(kernelSize/2); y++){
r = 0;
g = 0;
b = 0;
for(int i = -kernelSize/2; i<= kernelSize/2; i++){
for(int j = -kernelSize/2; j<= kernelSize/2; j++){
color = QColor(origin->pixel(x+i, y+j));
r += color.red()*kernel[kernelSize/2+i][kernelSize/2+j];
g += color.green()*kernel[kernelSize/2+i][kernelSize/2+j];
b += color.blue()*kernel[kernelSize/2+i][kernelSize/2+j];
}
}
r = qBound(0, r/sumKernel, 255);
g = qBound(0, g/sumKernel, 255);
b = qBound(0, b/sumKernel, 255);
newImage->setPixel(x,y, qRgb(r,g,b));
}
}
return newImage;
}
unsigned int CameraImageWrapper::gray(unsigned int r, unsigned int g, unsigned int b)
{
//values based on http://entropymine.com/imageworsener/grayscale/

View File

@ -34,8 +34,6 @@ private:
ArrayRef<char> getMatrixP() const;
QImage* grayScaleImage(const QImage *origin);
QImage* sharpen(const QImage *origin);
unsigned int gray(unsigned int r, unsigned int g, unsigned int b);
QImage* image;

View File

@ -198,25 +198,21 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
try {
Ref<LuminanceSource> imageRef(ciw);
GlobalHistogramBinarizer *binz = new GlobalHistogramBinarizer(imageRef);
Ref<Binarizer> bz(binz);
BinaryBitmap *bb = new BinaryBitmap(bz);
Ref<BinaryBitmap> ref(bb);
Ref<GlobalHistogramBinarizer> binz( new GlobalHistogramBinarizer(imageRef) );
Ref<BinaryBitmap> bb( new BinaryBitmap(binz) );
DecodeHints hints((int)enabledDecoders);
bool hasSucceded = false;
try {
res = decoder->decode(ref, hints);
res = decoder->decode(bb, hints);
hasSucceded = true;
}catch(zxing::Exception &e){}
if(!hasSucceded)
{
hints.setTryHarder(true);
res = decoder->decode(ref, hints);
res = decoder->decode(bb, hints);
}
QString string = QString(res->getText()->getText().c_str());

View File

@ -52,7 +52,6 @@ Ref<LuminanceSource> BinaryBitmap::getLuminanceSource() const {
return binarizer_->getLuminanceSource();
}
bool BinaryBitmap::isCropSupported() const {
return getLuminanceSource()->isCropSupported();
}
@ -68,3 +67,8 @@ bool BinaryBitmap::isRotateSupported() const {
Ref<BinaryBitmap> BinaryBitmap::rotateCounterClockwise() {
return Ref<BinaryBitmap> (new BinaryBitmap(binarizer_->createBinarizer(getLuminanceSource()->rotateCounterClockwise())));
}
Ref<zxing::BinaryBitmap> BinaryBitmap::rotateCounterClockwise45()
{
return Ref<BinaryBitmap> (new BinaryBitmap(binarizer_->createBinarizer(getLuminanceSource()->rotateCounterClockwise45())));
}

View File

@ -45,10 +45,10 @@ namespace zxing {
bool isRotateSupported() const;
Ref<BinaryBitmap> rotateCounterClockwise();
Ref<BinaryBitmap> rotateCounterClockwise45();
bool isCropSupported() const;
Ref<BinaryBitmap> crop(int left, int top, int width, int height);
};
}

View File

@ -46,6 +46,11 @@ Ref<LuminanceSource> LuminanceSource::rotateCounterClockwise() const {
throw IllegalArgumentException("This luminance source does not support rotation.");
}
Ref<zxing::LuminanceSource> LuminanceSource::rotateCounterClockwise45() const
{
throw IllegalArgumentException("This luminance source does not support rotation 45.");
}
LuminanceSource::operator std::string() const {
ArrayRef<char> row;
std::ostringstream oss;

View File

@ -51,6 +51,8 @@ class LuminanceSource : public Counted {
virtual Ref<LuminanceSource> rotateCounterClockwise() const;
virtual Ref<LuminanceSource> rotateCounterClockwise45() const;
operator std::string () const;
};

View File

@ -48,9 +48,10 @@ void GlobalHistogramBinarizer::initArrays(int luminanceSize) {
if (luminances->size() < luminanceSize) {
luminances = ArrayRef<char>(luminanceSize);
}
for (int x = 0; x < LUMINANCE_BUCKETS; x++) {
buckets[x] = 0;
}
// for (int x = 0; x < LUMINANCE_BUCKETS; x++) {
// buckets[x] = 0;
// }
memset(&buckets[0], 0, sizeof(int) * LUMINANCE_BUCKETS);
}
Ref<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> row) {

View File

@ -107,9 +107,7 @@ bool FinderPatternFinder::foundPatternCross(int* stateCount) {
float FinderPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal) {
int maxI = image_->getHeight();
int stateCount[5] = {0};
// for (int i = 0; i < 5; i++)
// stateCount[i] = 0;
int *stateCount = getCrossCheckStateCount();
// Start counting up from center
@ -175,9 +173,7 @@ float FinderPatternFinder::crossCheckHorizontal(size_t startJ, size_t centerI, i
int originalStateCountTotal) {
int maxJ = image_->getWidth();
int stateCount[5] = {0};
// for (int i = 0; i < 5; i++)
// stateCount[i] = 0;
int *stateCount = getCrossCheckStateCount();
int j = startJ;
while (j >= 0 && image_->get(j, centerI)) {
@ -312,7 +308,7 @@ bool FinderPatternFinder::haveMultiplyConfirmedCenters() {
// and that we need to keep looking. We detect this by asking if the estimated module sizes
// vary too much. We arbitrarily say that when the total deviation from average exceeds
// 5% of the total module size estimates, it's too much.
float average = totalModuleSize / max;
float average = totalModuleSize / (float)max;
float totalDeviation = 0.0f;
for (size_t i = 0; i < max; i++) {
Ref<FinderPattern> pattern = possibleCenters_[i];
@ -537,7 +533,16 @@ Ref<FinderPatternInfo> FinderPatternFinder::find(DecodeHints const& hints) {
}
vector< Ref <FinderPattern> > patternInfo = selectBestPatterns();
patternInfo = orderBestPatterns(patternInfo);
vector< Ref <ResultPoint> > patternInfoResPoints;
for(size_t i=0; i<patternInfo.size(); i++)
patternInfoResPoints.push_back(Ref<ResultPoint>(patternInfo[i]));
ResultPoint::orderBestPatterns(patternInfoResPoints);
patternInfo.clear();
for(size_t i=0; i<patternInfoResPoints.size(); i++)
patternInfo.push_back(Ref<FinderPattern>(static_cast<FinderPattern*>( &*patternInfoResPoints[i] )));
Ref<FinderPatternInfo> result(new FinderPatternInfo(patternInfo));
return result;