www.pudn.com > MediaPlayer.rar > MyBmp.h


#ifndef	MY_BMP 
#define MY_BMP	1 
 
#include  
#include  
#include  
#include  
#include  
#include  
 
#define WIDTHBYTES(bits)    (((bits) + 31) / 32 * 4) 
#define sqr(x)    ((x)*(x)) 
#define pow(x)		((x)*(x)*(x)) 
 
 
#define MULU				"E:\\work\\test\\c\\ww\\source\\*.bmp" 
#define READ				"F:\\¹Ø¼üÖ¡\\ͼ\\%d.bmp" 
#define RESULT				"E:\\work\\test\\c\\ww\\result\\%d.bmp"	 
#define TXT					"E:\\work\\test\\c\\ww\\result\\result.txt" 
 
#define PI 3.14159 
#define MY_MAX   255 
#define simg 1 
#define eimg 200 
//±ß¿òλÖà 
 
 
 
struct Point 
{ 
	int x; 
	int y; 
}; 
typedef struct node  
{ 
	int keynum ; 
	int start,lenth ; 
	float * center ; 
	float entropyMax ; 
	struct node *next ; 
}Childshot; 
 
class MyBmp 
{ 
public: 
	MyBmp(){}; 
	virtual ~MyBmp(){}; 
   /********************** 
	*function :  
	*          read image data from '*.bmp' file 
    * 
    *parameter:  
	*          int &width    : the width of the image 
	*		  int &height   : the height of the image 
	*		  char *bmpname : name of the image file 
    * 
    *return value: 
	*             unsigned char* , the image data stored in windows format 
	***********************/ 
	unsigned char *ReadBMPData(int &width, int &height,char *bmpname); 
 
 
   /********************** 
	*function :  
	*           save image data into '*.bmp' file 
    * 
    *parameter :  
	*           unsigned char* : image data stored in the memory, 
	*		                  in windows format not the bmp data format  
	*           int &width     : the width of the image 
	*		   int &height    : the height of the image 
	*		   char *bmpname  : name of the image file which you want to save 
    * 
    *return value: 
	*             void 
	***********************/ 
	void SaveBMPData(unsigned char *imageData, int width, int height, char *bmpname, int nType); 
 
 
   /*********************** 
	*function :  
	*           binary the image in the otsu methods 
    * 
    *parameter :  
	*           unsigned char* : image data stored in the memory, 
	*		                  in windows format not the bmp data format  
	*           int lWidth     : the width of the image 
	*		   int lHeight    : the height of the image 
	*		   
    *return value: 
	*             BOOL 
	***********************/ 
//	BOOL ThresholdOtsuDIB(unsigned char *lpDIBBits, int lWidth, int lHeight); 
 
 
	 /******************** 
	  *function :  
	  *         binary the image in the iterative methods 
      * 
      *parameter :  
	  *         unsigned char* : image data stored in the memory, 
	  *		                    in windows format not the bmp data format  
	  *         int lWidth     : the width of the image 
	  *		   int lHeight    : the height of the image 
	  *		   
      *return value: 
	  *           BOOL 
	  ********************/ 
//	BOOL ThresholdIteraDIB(unsigned char *lpDIBBits, int lWidth, int lHeight); 
 
 
	/********************** 
	 *function :  
	 *          crop the image from the coordinate(x,y); 
     * 
     *parameter :  
	 *           unsigned char* :   image data stored in the memory, 
	 *		                      in windows format not the bmp data format  
	 *          int imgWidth     : the width of the image 
	 *		   int imgHeight    : the height of the image 
	 *		   int cropHeight   : the height of the processed image 
	 *		   int cropWidth    : the width of the processed image 
	 *		   int x            : crop the image from the coordinate(x,y); 
	 *		   int y            : crop the image from the coordinate(x,y); 
	 *		   
     *return value: 
	 *            unsigned char* : the image data of the croped image. 
	 *********************/ 
//	unsigned char* imcropImg(unsigned char *Img, int imgWidth, int imgHeight, int cropWidth, int cropHeight, int x, int y); 
    
    /********************** 
	 *function :  
	 *          scale the image in the binaryLinear methods 
     * 
     *parameter :  
	 *          unsigned char* : image data stored in the memory, 
	 *		                    in windows format not the bmp data format  
	 *          int lWidth     : the width of the image 
	 *		   int lHeight    : the height of the image 
	 *		   float scalTimes: if 'scalTimes' is between (0-1) shrink the image,  
	 *	                    else if 'scalTime' is bigger than 1.0 
	 *		                    largen the image 
	 *		   
     *return value: 
	 *            unsigned char*: return the processed image data. 
	 *********************/ 
//	unsigned char *BiLinearImg(unsigned char *lpDIBBits, int lWidth, int lHeight, float scalTimes); 
 
   /********************** 
	*function :  
	*           rotate the image  
    * 
    *parameter :  
	*           unsigned char* : image data stored in the memory, 
	*		                    in windows format not the bmp data format  
	*           int lWidth     : the width of the image 
	*		   int lHeight    : the height of the image 
	*		   float angel    : rotate the image in the clock direction 
	*		   char* fileName : save the rotated image in this file 
	*		   
    *return value: 
	*            void 
	***********************/ 
//	void RotateImg(unsigned char *lpDIBBits, int lWidth, int lHeight, float angle, char* fileName); 
    
 
   /********************** 
	*function :  
	*           process the image using template  
    * 
    *parameter :  
	*          unsigned char* : image data stored in the memory, 
	*		                    in windows format not the bmp data format  
	*           int lWidth     : the width of the image 
	*		    int lHeight    : the height of the image 
	*		    bool isX       : use the template to detect the edge in X-axes direction		   			   
    *return value: 
	*            void 
	***********************/ 
//	void EdgeDetect(unsigned char *lpDIBBits, int lWidth, int lHeight, bool isX); 
 
    /********************** 
	*function :  
	*           match the template image in the source iamge 
    * 
    *parameter :  
	*          unsigned char* : source image data stored in the memory, 
	*		                    in windows format not the bmp data format  
	*          int sWidth    : the width of the source image 
	*		   int sHeight    : the height of the sourceimage 
   	*          unsigned char* : template image data stored in the memory, 
	*		                    in windows format not the bmp data format  
	*		   			   			   
    *return value: 
	*            Point        : the start point of the matched image 
	***********************/ 
//	Point TemplateMatch(unsigned char *sourceImage, int sWidth, int sHeight, unsigned char *templateImage, int tWidth, int tHeight); 
 
	 /********************** 
	*function :  
	*           unify the image  
    * 
    *parameter :  
	*          unsigned char* : source image data stored in the memory, 
	*		                    in windows format not the bmp data format  
	*          int sWidth     : the width of the source image 
	*		   int sHeight    : the height of the sourceimage 
   	*          int rWidth     : the width of the result image 
	*		   int rHeight    : the height of the result image 
	*           
	*		   			   			   
	*             
	***********************/ 
//	void UnifyImg(unsigned char *lpDIBBits, int sWidth, int sHeight, int rWidth, int rHeight, char* fileName); 
 
	 
//    void RecogniseChar(unsigned char *lpDIBBits, int id); 
 
	/********************** 
	*function :  
	*           delete the edge which gray value is 255  
    * 
    *parameter :  
	*          unsigned char* : source (binary)image data stored in the memory, 
	*		                    in windows format not the bmp data format  
	*          int sWidth     : the width of the source image 
	*		   int sHeight    : the height of the sourceimage 
   	*          int rWidth     : the width of the result image 
	*		   int rHeight    : the height of the result image 
	*           
	*Result    : 
	*           Point         :return the new start point of the image   
	***********************/ 
//	Point DeleteEdgeImg(unsigned char *lpDIBBits, int sWidth, int sHeight, int &rWidth, int &rHeight); 
	 
 
	/********************** 
	*function :  
	*           caculate the every pixel's grads in the image 
    * 
    *parameter :  
	*          unsigned char* : source image data stored in the memory, 
	*		                    in windows format not the bmp data format  
	*          int lWidth     : the width of the source image 
	*		   int lHeight    : the height of the sourceimage 
	*           
	*Result    : 
	*           double*         :return the grads array   
	***********************/ 
//	double *CaculateGrads(unsigned char *lpDIBBits, int lWidth, int lHeight); 
 
	/********************** 
	*function :  
	*           equalize the image 
    * 
    *parameter :  
	*          unsigned char* : source image data stored in the memory, 
	*		                    in windows format not the bmp data format ,the processed result 
	*                           was stored this block memory too 
	*          int lWidth     : the width of the source image 
	*		   int lHeight    : the height of the source image 
	*           
	*Result    : 
	*           bool         :return true if processd correctly   
	***********************/ 
//	bool EqualImage(unsigned char *lpDIBBits, int lWidth, int lHeight); 
 
	/********************** 
	*function :  
	*           Get the letter's character 
    * 
    *parameter :  
	*          unsigned char* : source image data stored in the memory, 
	*		                    in windows format not the bmp data format ,the processed result 
	*                           was stored this block memory too 
	*          int lWidth     : the width of the source image 
	*		   int lHeight    : the height of the source image 
	*           
	*Result    : 
	*           float*         :return a float array filled with the character of the letter   
	***********************/ 
//	float *GetCharacter(unsigned char *bmpData, unsigned char *threshData, int lWidth, int lHeight); 
 
//	bool Erosion(unsigned char *lpDIBBits, int lWidth, int lHeight, bool Hori, PROWINDOW ProcessWindow); 
//	bool Dilation(unsigned char *lpDIBBits, int lWidth, int lHeight, bool Hori, PROWINDOW ProcessWindow); 
//	unsigned char *ImgSubtract(unsigned char *lpImgData1, unsigned char *lpImgData2,  
//		                       int Width, int Height); 
//	unsigned char *ImgAdd(unsigned char *lpImgData1, unsigned char *lpImgData2,  
//							   int Width, int Height); 
//	bool ThresholdTrans(unsigned char* lpDIBBits, LONG lWidth, LONG lHeight, BYTE bThre); 
	//void ImgSub(char *bmpFileName1, char *bmpFileName2, unsigned int &width, unsigned int &height, unsigned char *&Sub256Img, unsigned char *&Sub2Img, 
	//			unsigned char *&bmpData1, unsigned char *&bmpData2, int grp, int num); 
//	unsigned char* ImgAnd(unsigned char *lpImgData1, unsigned char *lpImgData2,  
//						   int Width, int Height); 
//	unsigned char* ImgOr(unsigned char *lpImgData1, unsigned char *lpImgData2,  
//						   int Width, int Height); 
//	void Imgcontrast(unsigned char *&lpImgData1,  int Width, int Height);  
//	void Img256contrast(unsigned char *lpImgData1,  int Width, int Height); 
//	int LabelRegion(unsigned char *pImage,int width, int height, int border, int grayLevel, int startIndex, int *label,int num[],int connect, PROWINDOW ProcessWindow); 
//	void ImgCut(unsigned char *ImgData, int width, int height, unsigned int &Left, unsigned int &Right); 
//	void ImgBorder(unsigned char *ImgData1, unsigned char *ImgData2, unsigned char *ImgData3, 
	//			unsigned char *ImgData4, unsigned char *ImgData5, unsigned char *ImgData6, 
	//		int width, int height, unsigned int &left, unsigned int &right); 
//	void ImgRemove(unsigned char *ImgData, int width, int height, unsigned int left, unsigned int right); 
//	unsigned char* ImgSub6(unsigned char *ImgData1, unsigned char *ImgData2, unsigned char *ImgData3, 
//								  unsigned char *ImgData4, unsigned char *ImgData5, unsigned char *ImgData6, 
//				                  int width, int height); 
//	unsigned char* ImgSub5(unsigned char *ImgData1, unsigned char *ImgData2, unsigned char *ImgData3, 
//								  unsigned char *ImgData4, unsigned char *ImgData5, 
//				                  int width, int height); 
//	PARTICLE* Result(unsigned char *SubImg, int width, int height, PROWINDOW ProcessWindow, int	&no_of_select, int Thresh); 
//	void GetHistogram(unsigned char* ImgData, int width, int height, double *lHistogram); 
//	void MinimumBias(unsigned char *pImage, int width, int height, int &pThreshold, PROWINDOW ProcessWindow); 
//	bool ErosionBig(unsigned char *lpDIBBits, int lWidth, int lHeight, int tl, PROWINDOW ProcessWindow); 
//	bool DilationBig(unsigned char *lpDIBBits, int lWidth, int lHeight, int tl, PROWINDOW ProcessWindow); 
//	bool MedianFilter(unsigned char* hImgData, int lwidth, int lheight, bool Hori, PROWINDOW ProcessWindow); 
	unsigned char* CopyImg(unsigned char *Image, int Width, int Height, int k) ; 
//	void ParticleDectection(unsigned char *Image, int Width, int Height, int ImageNumber,  
//				   PROWINDOW ProcessWindow, PARTICLE * &result, int &ParticleNumber, int Thresh, unsigned char * &outImage); 
//	void wwang(int *Label,int width,int height,int *pnum,PROWINDOW ProcessWindow, int &no_of_regions); 
//	void DivBox(int width, int height, PROWINDOW ProcessWindow, PROWINDOW DivProWin[]); 
//	void DivideThreshold(unsigned char* ImgData, PROWINDOW *DivProWin, int width, int height, int &pThreshold); 
 
//	void ParticleDectectionOpticalFlow(unsigned char *Image, int Width, int Height, int ImageNumber,  
//				   PROWINDOW ProcessWindow, PARTICLE * &result, int &ParticleNumber, int Thresh, unsigned char * &outImage); 
 //   void ParticleDectectionCombined(unsigned char *Image,int width, int height,int ImageNumber, PROWINDOW ProcessWindow, PARTICLE * &result, int &ParticleNumber, int Thresh, unsigned char * &outImage); 
//	void LinkingDot(int i, int j, int k, int l, int width, int height, int *label, int *pnum); 
//	void Release(PARTICLE * &ParticleResult); 
	void Rgb2Hsv(unsigned char * Image, int Width, int Height , float * TepImg , int loop) ; 
	void Hist_hsv(float * TepImg , int * Hist_hsv,int loop , int Width, int Height) ; 
	void Hist_hsv1(float * TepImg , int * Hist_hsv,int loop , int Width, int Height) ; 
	int  value(float H , float S , float V) ; 
	int value1(float H , float S , float V) ; 
	void FrameExaction(float * TepImg , int * Hist_hsv , int * result , int sframe , int eframe , int Width, int Height) ; 
	void conv(int * Hist_hsv1 , int * result , int sframe , int eframe, int m) ; 
	void cluster(float * TepImg , int * result , int &i , int ed , int Width, int Height , int * Hist_hsv) ; 
	void Feature(float * TepImg , int Width, int Height , float *vector) ; 
	void Distance(float *vector1 , float *vector2 , float &distance) ; 
	void Entropy(int * Hist_hsv , float &entropyMax , int &keynum , int Width, int Height , int i) ; 
}; 
 
#endif