twain2/ImageRotation.cpp

61 lines
1.2 KiB
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::setRotationFlip(int flip)
{
m_nRotation = flip;
}
int CImageRotation::getRotetion()
{
return m_nRotation;
}
void CImageRotation::apply(cv::Mat & pDib, int side)
{
//FileTools::write_log("D:\\1.txt", "enter CImageRotation apply");
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);
}
}
//FileTools::write_log("D:\\1.txt", "exit CImageRotation apply");
}