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

📄 fnbitmap.cpp

📁 在人脸检测的基础之上,对嘴部的运动表情进行分析,进行语音模拟.
💻 CPP
字号:
// FnBitmap.cpp: implementation of the FnBitmap class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SeqProcess.h"
#include "FnBitmap.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//------------------------------------------------------
// Converts a dib( device independent bitmap) image
// to an image kept in a matrix with double elements
// If the image is colored, 3 bands are created of size 
// yszie x xsize. They contain R, G, and B components
// respectively.
//-------------------------------------------------------
void ConvertDib2Mat( matrix& mat, const CDib& dib)
{
	int xsize = dib.m_lpBMIH->biWidth;
	int ysize = dib.m_lpBMIH->biHeight;
	int numbands = dib.m_lpBMIH->biBitCount / 8;

	mat = matrix(ysize, xsize, numbands);

	LPBYTE pBmp;
	double* pMat;
	
	for ( int u = 0; u < numbands; ++u)
	{
		int offset = u * ysize * xsize;
		pBmp = dib.m_lpImage + numbands - 1 - u;
		for ( int j = 0; j < ysize; ++j)
		{
			pMat = mat.elem + offset + (ysize - 1 - j) * xsize;
			for ( int i = 0; i < xsize; ++i, pBmp += numbands, pMat++)
			{
				*pMat = (double) *pBmp;
			}
		}
	}	
}
//----------------------------------------------------
// Converts a matrix image into bitmap assuming that 
// the bitmap image has been initialized and the 
// height and width of them are the same. 
//----------------------------------------------------
void ConvertMat2Dib( CDib& dib, const matrix& mat)
{
	// assumes dib has the same size as mat
	int xsize = mat.xsize;
	int ysize = mat.ysize;
	int numbands = mat.numbands;

	ASSERT( xsize*ysize*numbands == dib.m_lpBMIH->biBitCount / 8 
		* dib.m_lpBMIH->biWidth * dib.m_lpBMIH->biHeight);

	LPBYTE pBmp;
	double* pMat;
	int val;

	for (int u = 0; u < numbands; ++u)
	{		
		int offset = ( numbands - 1 - u) * ysize * xsize;
		pBmp = dib.m_lpImage + u;
		for ( int j = 0; j < ysize; ++j)
		{
			pMat = mat.elem + offset + (ysize - 1 - j) * xsize;
			for ( int i = 0; i < xsize; ++i, pBmp += numbands, pMat++)
			{
				val = (int)(0.5 + *pMat);
				if( val > 255) val = 255;
				else if( val < 0) val = 0;
				*pBmp = (BYTE)val;
			}
		}
	}
}

⌨️ 快捷键说明

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