📄 hwpreview.cpp
字号:
::DIBToIntArray(lpDIB,0,0,31,31,image,32,32,ID_IMAGE_01);
savetofile sf;
sf.filesave(image,32,32);
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB2());
double * TransformResult = new double [64];
((CMainFrame*)AfxGetMainWnd())->SetMessageText("正在准备 Gabor 核函数...");
FFTGabor gabor(31,64);
gabor.PrepareKernel();
/*
//单核函数测试
FFTGaborResult * result = new FFTGaborResult(128) ;
for(int Orientation=0; Orientation<8; Orientation++)
for(int Frequency=0; Frequency<4; Frequency++)
{
gabor.GaborTransform(image,128,128,Orientation,Frequency,result);
TransformResult[(Orientation * 4 + Frequency) * 2] = result->Avg;
TransformResult[(Orientation * 4 + Frequency) * 2 + 1] = result->Deta;
}
delete result;
*/
/*
//全部核函数
gabor.GaborTransform(image,128,128,TransformResult);
*/
/*
//全部核函数--复数数组
complex<double> *TD = new complex<double>[256 * 256];
gabor.intTocomplex(TD,image,128,128);
gabor.GaborTransform(TD,128,128,TransformResult);
delete [] TD;
*/
/*
*/ //单核函数测试--复数数组
complex<double> *TD = new complex<double>[64 * 64];
gabor.intTocomplex(TD,image,32,32);
FFTGaborResult * result = new FFTGaborResult(32) ;
for(int Orientation=0; Orientation<8; Orientation++)
for(int Frequency=0; Frequency<4; Frequency++)
{
gabor.GaborTransform(TD,32,32,Orientation,Frequency,result);
TransformResult[(Orientation * 4 + Frequency) * 2] = result->Avg;
TransformResult[(Orientation * 4 + Frequency) * 2 + 1] = result->Deta;
}
delete result;
delete [] TD;
//
delete [] image;
delete [] TransformResult;
// 恢复光标
EndWaitCursor();
}
void CHwpreView::OnEditSelect()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
// 指向DIB的指针
LPSTR lpDIB;
// 创建新DIB
HDIB hNewDIB = NULL;
//pDoc->HDIBCOPYTOHDIB2();
// 锁定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB2());
CRect cr,*pcr,crDest;int i = 0,k,j ; POSITION pst;
k = j = 134;
crDest =CRect(30,60,583,210);
if (!m_ListRect.IsEmpty()) {
pst = m_ListRect.GetHeadPosition();
do {
pcr = ((CRect * ) m_ListRect.GetAt(pst));
cr = *pcr;
if (cr.top >= crDest.top && (cr.top - crDest.top)<j ) {
j = cr.top - crDest.top;
}
if (cr.bottom <= crDest.bottom && (crDest.bottom - cr.bottom) <k) {
k = crDest.bottom - cr.bottom;
}
m_ListRect.GetNext(pst);
i++;
} while(i<m_ListRect.GetCount());
}
crDest.top = crDest.top +j;
crDest.bottom = crDest.bottom -k;
crDest.NormalizeRect();
int * image = new int[(crDest.Height()+1)*(crDest.Width()+1)]; //(30,66) (583,200)
::DIBToIntArray(lpDIB,crDest.left,crDest.top,crDest.right,crDest.bottom,image,(crDest.Width()+1),(crDest.Height()+1),ID_IMAGE_255);
hNewDIB = (HDIB) IntArrayToDIB(lpDIB,image,(crDest.Width()+1),(crDest.Height()+1),ID_IMAGE_255);
delete [] image;
if (hNewDIB != NULL) {
pDoc->ReplaceHDIB2(hNewDIB);
pDoc->InitDIBData2();
pDoc->UpdateAllViews(NULL);
}
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB2());
}
//我自愿参加高等教育自学考试努力学习知识技能遵守国家有关的法律法规和规定按要求向考试管理机构提供我本人的真实信息以维护国家考试的威严
//处理样例汉字,如上共65个
void CHwpreView::OnOriHanzi()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
// 指向DIB的指针
LPSTR lpDIB;
pDoc->HDIBCOPYTOHDIB2();
// 锁定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB2());
// 更改光标形状
BeginWaitCursor();
int * image = new int[128*128]; //128*128
int i ,j;
double * TransformResult = new double [64];
double * TF = new double[65*64];
((CMainFrame*)AfxGetMainWnd())->SetMessageText("正在准备 Gabor 核函数...");
FFTGabor gabor(101,256);
gabor.PrepareKernel();
for (i= 0; i< 65;i++) {
TRACE1("i= %d start",i);
::DIBToIntArray(lpDIB,i * 128,0,i*128+127,127,image,128,128,ID_IMAGE_01);
//全部核函数
gabor.GaborTransform(image,128,128,TransformResult);
for (j =0 ;j<64;j++) {
TF[i*64+j] = TransformResult[j];
}
TRACE1("i= %d end\n",i);
}
savetofile sf;
sf.filesave(TF,64,65);
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB2());
/*
//单核函数测试
FFTGaborResult * result = new FFTGaborResult(128) ;
for(int Orientation=0; Orientation<8; Orientation++)
for(int Frequency=0; Frequency<4; Frequency++)
{
gabor.GaborTransform(image,128,128,Orientation,Frequency,result);
TransformResult[(Orientation * 4 + Frequency) * 2] = result->Avg;
TransformResult[(Orientation * 4 + Frequency) * 2 + 1] = result->Deta;
}
delete result;
*/
/*
*/
/*
//全部核函数--复数数组
complex<double> *TD = new complex<double>[256 * 256];
gabor.intTocomplex(TD,image,128,128);
gabor.GaborTransform(TD,128,128,TransformResult);
delete [] TD;
*/
/*
//单核函数测试--复数数组
complex<double> *TD = new complex<double>[256 * 256];
gabor.intTocomplex(TD,image,128,128);
FFTGaborResult * result = new FFTGaborResult(128) ;
for(int Orientation=0; Orientation<8; Orientation++)
for(int Frequency=0; Frequency<4; Frequency++)
{
gabor.GaborTransform(TD,128,128,Orientation,Frequency,result);
TransformResult[(Orientation * 4 + Frequency) * 2] = result->Avg;
TransformResult[(Orientation * 4 + Frequency) * 2 + 1] = result->Deta;
}
delete result;
delete [] TD;
*/
//
delete [] image;
delete [] TransformResult;
delete [] TF;
// 恢复光标
EndWaitCursor();
}
void CHwpreView::OnOriHanzi32()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
// 指向DIB的指针
LPSTR lpDIB;
pDoc->HDIBCOPYTOHDIB2();
// 锁定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB2());
// 更改光标形状
BeginWaitCursor();
int * image = new int[32*32]; //128*128
int i ,j;
double * TransformResult = new double [64];
double * TF = new double[65*64];
savetofile sf;
((CMainFrame*)AfxGetMainWnd())->SetMessageText("正在准备 Gabor 核函数...");
FFTGabor gabor(31,64);
gabor.PrepareKernel();
for (i= 0; i< 65;i++) {
TRACE1("i= %d start",i);
::DIBToIntArray(lpDIB, i * 32,0 ,i*32+31,31,image,32,32,ID_IMAGE_01);
//全部核函数
gabor.GaborTransform(image,32,32,TransformResult);
for (j =0 ;j<64;j++) {
TF[i*64+j] = TransformResult[j];
}
TRACE1("i= %d end\n",i);
}
sf.filesave(TF,64,65);
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB2());
/*
//单核函数测试
FFTGaborResult * result = new FFTGaborResult(128) ;
for(int Orientation=0; Orientation<8; Orientation++)
for(int Frequency=0; Frequency<4; Frequency++)
{
gabor.GaborTransform(image,128,128,Orientation,Frequency,result);
TransformResult[(Orientation * 4 + Frequency) * 2] = result->Avg;
TransformResult[(Orientation * 4 + Frequency) * 2 + 1] = result->Deta;
}
delete result;
*/
/*
*/
/*
//全部核函数--复数数组
complex<double> *TD = new complex<double>[256 * 256];
gabor.intTocomplex(TD,image,128,128);
gabor.GaborTransform(TD,128,128,TransformResult);
delete [] TD;
*/
/*
//单核函数测试--复数数组
complex<double> *TD = new complex<double>[256 * 256];
gabor.intTocomplex(TD,image,128,128);
FFTGaborResult * result = new FFTGaborResult(128) ;
for(int Orientation=0; Orientation<8; Orientation++)
for(int Frequency=0; Frequency<4; Frequency++)
{
gabor.GaborTransform(TD,128,128,Orientation,Frequency,result);
TransformResult[(Orientation * 4 + Frequency) * 2] = result->Avg;
TransformResult[(Orientation * 4 + Frequency) * 2 + 1] = result->Deta;
}
delete result;
delete [] TD;
*/
//
delete [] image;
delete [] TransformResult;
delete [] TF;
// 恢复光标
EndWaitCursor();
}
void CHwpreView::OnEditCopy1to2()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
pDoc->HDIBCOPYTOHDIB2();
}
void CHwpreView::OnEditCopy2to1()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
pDoc->HDIB2COPYTOHDIB();
}
void CHwpreView::OnSmooth()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
HDIB hDib = pDoc->GetHDIB2();
LPSTR lpDib = (LPSTR) GlobalLock((HGLOBAL) hDib);
LPSTR lpDibBits = ::FindDIBBits(lpDib);
LONG lHeight = ::DIBHeight(lpDib);
LONG lWidth = ::DIBWidth(lpDib);
LONG m_lLineBytes = WIDTHBYTES(lWidth*8 );
LPBYTE hbits;
int * lCount = new int[lHeight];
HprojectDIB2(lpDib,lCount,0,0,lWidth-1,lHeight-1);
Smoth(lCount,lHeight,3);
memset(lpDibBits,(BYTE)255, lHeight * m_lLineBytes);
int i, j ;
for (i= 0;i < lHeight;i++) {
for (j= 1;j<=lCount[i];j++) {
hbits = (LPBYTE ) lpDibBits + m_lLineBytes * (lHeight -1 -i) + j;
* hbits = 0;
}
}
delete[] lCount;
GlobalUnlock((HGLOBAL) hDib);
pDoc->UpdateAllViews(NULL);
}
void CHwpreView::OnSmoothV()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
HDIB hDib = pDoc->GetHDIB2();
LPSTR lpDib = (LPSTR) GlobalLock((HGLOBAL) hDib);
LPSTR lpDibBits = ::FindDIBBits(lpDib);
LONG lHeight = ::DIBHeight(lpDib);
LONG lWidth = ::DIBWidth(lpDib);
LONG m_lLineBytes = WIDTHBYTES(lWidth*8 );
LPBYTE hbits;
int * lCount = new int[lWidth];
VprojectDIB2(lpDib,lCount,0,0,lWidth-1,lHeight-1);
Smoth(lCount,lWidth,3);
memset(lpDibBits,(BYTE)255, lHeight * m_lLineBytes);
int i, j ;
for (i= 0;i < lWidth;i++) {
for (j= 1;j<=lCount[i];j++) {
hbits = (LPBYTE ) lpDibBits + m_lLineBytes * ( j - 1 ) + i;
* hbits = 0;
}
}
delete[] lCount;
GlobalUnlock((HGLOBAL) hDib);
pDoc->UpdateAllViews(NULL);
}
void CHwpreView::OnEdHega3()
{
// TODO: Add your command handler code here
CHwpreDoc * pDoc = GetDocument();
HDIB hDib = pDoc->GetHDIB2();
LPSTR lpDib = (LPSTR) GlobalLock((HGLOBAL) hDib);
LPSTR lpDibBits = ::FindDIBBits(lpDib);
LONG lHeight = ::DIBHeight(lpDib);
LONG lWidth = ::DIBWidth(lpDib);
LONG m_lLineBytes = WIDTHBYTES(lWidth*8 );
LPBYTE hbits;
LONG lSize = lHeight;
int * lCount = new int[lSize]; //投影
int * lCount1 =new int[lSize];
int * lTeam = new int[lSize]; //分组组号
int iLines=1,iLastLines=lSize+1; //分组数
int i, j , k;
LONG lLastDeta,lDeta;
LONG lSum =0,lAvg;
HprojectDIB2(lpDib,lCount,0,0,lWidth-1,lHeight-1);
j = 0;
for (i =0 ;i<lSize ;i++) {
if(lCount[i] >0){
lCount1[i] = lCount[i];
lSum += lCount[i];
j++;
}else{
lCount[i] =0;
lCount1[i]=0;
}
}
lAvg = lSum /j;
BOOL isBegin =FALSE;
j = 0;
do {
k = 0;
for (i = 0;i<lSize ;i++) {
lTeam[i] = 0;
}
//lLastDeta = 0;
for (i = 0 ;i < lSize; i++) {
if (i == lSize -1) {
lLastDeta = lDeta;
lDeta = 1;
}else {if(i == 0){
lLastDeta =-1;
lDeta = lCount[i+1] - lCount[i];
}else{
if (lDeta !=0) {
lLastDeta = lDeta;}
lDeta = lCount[i+1] - lCount[i];
}}
//|| && lCount1[i] < lAvg
if ((lLastDeta < 0 && lDeta >0 && lCount1[i] < lAvg/2 ) || (i ==0 && lCount1[i] >0)) {
k ++ ; lTeam[i] = k; isBegin=TRUE; //区域开始
}else{
if (lLastDeta < 0 && (lDeta >0 ||lCount1[i]==0 ||i == lSize -1) && lCount1[i] < lAvg/2 && isBegin == TRUE ) {
lTeam[i] = k; isBegin = FALSE;
}else{ if (isBegin == FALSE) {
lTeam[i] =0;
}else{
lTeam[i] = k;
}}
}
}
iLines = k;
if (abs(iLines - iLastLines)<=1) {
j++; iLastLines=iLines; if(j>=8 ) break;
}else{
j= 0;
iLastLines = iLines ;
}
Smoth(lCount,lSize,3);
} while(j < 8);
//Smoth(lCount,lHeight,3);
//HDIB hnewDib = IntArrayToDIB(hDib,)
memset(lpDibBits,(BYTE)255, lHeight * m_lLineBytes);
for (i= 0;i < lSize;i++) {
for (j= 1;j<=lCount[i];j++) {
hbits = (LPBYTE ) lpDibBits + m_lLineBytes * (lSize -1 -i) + j;
* hbits = 0;
}
}
LineInfo * li , * lit;
li = LinesInfoHead;
while (li != NULL) {
lit = li;
li = li->next;
delete lit;
}
LinesInfoHead = NULL;
LinesInfoRear = NULL;
LinesInfoLength = 0;
m_ListRect.RemoveAll();
CRect cr;
k = 0;
for (i = 0 ;i < lSize ;i ++) {
if (i == lSize-1 ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -