⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readbarcode.h

📁 barcode readers [ from Image]
💻 H
字号:
/*
	CReadBarcode. Given an image, decode all the barcodes in it.

	Copyright (C) 2006  Jon A. Webb

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#ifndef ReadBarcode_h
#define ReadBarcode_h

#include "Array.h"
#include "Bars2Sym.h"
#include "Bars2SymFactory.h"
#include "Image.h"
#include "MeasureComponents.h"

class CWindowGc;

class CReadBarcode : public CBase
{
public:
/*!
  @function CReadBarcode
  
  @discussion Perform the first phase of two phase construction 
  */
  CReadBarcode();	

/*!
  @function ReadBarcode
  
  @discussion Create a CReadBarcode object.
  */
  static CReadBarcode* NewL();

private:
/*!
  @function ConstructL
  
  @discussion  Perform the second phase construction of a CReadBarcode object
  */
	void ConstructL();

public:
/*!
  @function ConstructL
  
  @discussion Destructor
  */
	~CReadBarcode();

	// Operations
public:
/*!
	@function DoItL
	@discussion Given an image and a rectangle within the image where the
		barcode lies, try to read the barcode and report back the
		barcode type and contents if one can be read.

	@param image: the image to be processed.
	@param rect: the rectangle where the barcode lies
	@param result -- true if the barcode was found, false if not
	*/
	void DoItL(Core::CImage image, TRect rect);

	void ShowBarcodeL(const TDesC& name, TDesC& code);
private:
	/*!
	  @function CropAndDetectEdgesL
	  @discussion Given an image, crop it to a given rectangle and
	      detect edges.
	  @param inputImage: the input image.
	  @param rect: the cropping rectangle
	  @param croppedImage: cropped image
	  @param edgeImage: edge-detected image.
	  */
	static void CropAndDetectEdgesL(
		Core::CImage inputImage, 
		TRect rect, 
		Core::CImage& croppedImage, 
		Core::CImage& edgeImage);

	/*!
	  @function CropAndStretchImageL
	  @discussion The input image has been rectified, etc. Stretch it
	    so that the barcode in it will be of an exact size, making the
		decoding easier.
	  @param inputImage: the input image.
	  @param nLeft: the approximate left edge of the barcode.
	  @param nRight: the approximate right edge of the barcode.
	  @param nHeighReduce: factor by which to reduce the height of the
	    image to average out noise and speed up processing.
	  @param inputWidth: the presumed width of the barcode.
	  @param targetWidth: the width we will stretch the image to.
	  @param outputImage: the output image.
	  */
	static void CropAndStretchImageL(
		Core::CImage inputImage, 
		TInt nLeft, 
		TInt nRight, 
		TInt nHeightReduce, 
		TInt inputWidth,
		TInt targetWidth,
		Core::CImage& outputImage);

		/*!
	  @function FindBarcodeEdgesL
	  @discussion Given an edge image (signed char)
	      fit lines to the left and right sides of the
		  detected edges, and return the y-intercept and slope
		  of each line.
	  @param edgeImage: the edge image.
	  @param aLeft: the y-intercept (row = 0 position) of the left side
	  @param bLeft: the slope (change in position from row to row)
		  of the right side.
	  @param aRight: the y-intercept of the right side
	  @param bRight: the slope of the right side
	  */
	static TBool FindBarcodeEdgesL(
		Core::CImage edgeImage, 
		TInt &aLeft, 
		TReal &bLeft, 
		TInt &aRight, 
		TReal &bRight);

	/*!
	  @function FindPreciseBarcodeLimitsL
	  @discussion After the barcode image has been cropped, normalized, and
	      rectified, this finds the precise left and right limits of the
		  barcode by looking for a change in the short-width average
		  brightness vs. the long-width average brightness.
	  @param imageBarcode: the cropped, rectified, and normalized image
	  @param bestLeftPos: the left edge of the barcode
	  @param bestRightPos: the right edge of the barcode
	  */
	static void FindPreciseBarcodeLimitsL(
		Core::CImage imageBarcode, 
		TInt& bestLeftPos, 
		TInt& bestRightPos);

	/*!
	  @function FormShortAndLongSumsL
	  @discussion Sum an array over a short and long width.
	  @param pAvg: input array
	  @param shortWidth: short width
	  @parm longWidth: long width
	  @param pShortSum: sum over short range. element i = sum of pAvg(i-shortWidth...i+shortWidth)
	  @param pLongSum: sum over long range. element i = sum of pAvg(i-longWidth...i+longWidth)
	  */
	static void FormShortAndLongSumsL(
		Core::CArray<unsigned char>* pAvg, 
		TInt shortWidth,
		TInt longWidth,
		Core::CArray<TInt>*& pShortSum, 
		Core::CArray<TInt>*& pLongSum);

	/*!
	  @function RectifyBarcodeL
	  @discussion Rectify the input image so the barcode edges,
	     which are defined by the lines aLeft+row*bLeft and
		 aRight+row*bRight, become vertical. Include a bit of the 
		 quiet area on either side of the image.
	  @param inputImage: input image.
	  @param aLeft: left y-crossing
	  @param bLeft: left slope
	  @param aRight: right y-crossing
	  @param bRight: right slope
	  @param outputImage: output image
	 */
	static void RectifyBarcodeL(
		Core::CImage inputImage,
		TInt aLeft, 
		TReal bLeft, 
		TInt aRight, 
		TReal bRight,
		Core::CImage& outputImage);

	/*!
	  @function ZeroesToPointsL
	  @discussion After image processing has detected an array of zero
	      crossings in the barcode, this function takes the first
		  (if bLeft is true) or last (if bLeft is false) element
		  of each array as a position and returns it in a points
		  array for line fitting.
	  @param zeroes: the array of zero croessings.
	  @param points: the returned array of points.
	  @param bLeft: whether to return points on the left or right.
	 */
	static void ZeroesToPointsL(
		Core::CArray<CArrayFixFlat<TReal>*>& zeroes,
		CArrayFixFlat<TPoint>& points,
		TBool bLeft
		);

	// Accessors
public:
	TBool ReadOk() const;
private:

private:
	/*! @var iBars2SymFactory access to bar decoders */
	Barcode::CBars2SymFactory* iBars2SymFactory;

	/*! @var iFsSession the file session */
	RFs iFsSession;

	/*! @var iReadBarcode: true iff the barcode was successfully read */
	TBool iReadBarcode;

	/*! @var iRectangle: barcode bounding box */
	TRect iRectangle;
};

#endif // ReadBarcode_h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -