twain2/hugaotwainds/ImageRotation.cpp

49 lines
877 B
C++

#include "StdAfx.h"
#include "ImageRotation.h"
using namespace cv;
using namespace std;
CImageRotation::CImageRotation(int index_of_orentation,bool m_bBackRotate):m_nRotation(index_of_orentation),m_BackRotate(m_bBackRotate)
{
}
CImageRotation::~CImageRotation()
{
}
void CImageRotation::apply(cv::Mat & pDib,int side)
{
if (m_nRotation==4)//自动文本方向识别
{
}
else if (m_BackRotate&&side==1)//背面旋转180
{
if (m_nRotation!=2)//旋转180度
{
if (m_nRotation==1||m_nRotation==3)//90° -90°
{
transpose(pDib,pDib);
flip(pDib,pDib,m_nRotation==1?0:1);
}
else
{
flip(pDib,pDib,0);
flip(pDib,pDib,1);
}
}
}
else //zh
{
if (m_nRotation==1||m_nRotation==3)//90° -90°
{
transpose(pDib,pDib);
flip(pDib,pDib,m_nRotation==1?1:0);
}
else if(m_nRotation==2)
{
flip(pDib,pDib,0);
flip(pDib,pDib,1);
}
}
}