集成汉王ocr到pdf和ofd功能

This commit is contained in:
luoliangyi 2022-05-16 17:00:08 +08:00
parent 1198b95fb2
commit 704ea8eb4b
19 changed files with 114 additions and 41 deletions

View File

@ -42,7 +42,7 @@ Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
ui->lab_digitExp->setText(QString(tr("e.g. '%1%2'")).arg(ui->lineEdit_fileName->text())
.arg(ui->spin_index->value(), ui->cbox_digit->currentIndex() + 1, 10, QLatin1Char('0')));
ui->btn_option->setEnabled(0 == ui->cbox_format->currentIndex() || 3 == ui->cbox_format->currentIndex());
ui->cbtn_multiFile->setEnabled(ui->cbox_format->currentIndex() > 2);
ui->cbtn_multiFile->setEnabled(ui->cbox_format->currentIndex() > 2 && ui->cbox_format->currentIndex() < 6);
ui->radio_multiAll->setEnabled(ui->cbtn_multiFile->isChecked());
ui->radio_multiCustom->setEnabled(ui->cbtn_multiFile->isChecked());
ui->spinBox_multiPages->setEnabled(ui->cbtn_multiFile->isChecked() ? ui->radio_multiCustom->isChecked() : false);
@ -94,10 +94,17 @@ AquireIntoSaveParam Dialog_AquireInto::getSaveParam()
case 5:
format = "ofd";
break;
case 6:
format = "pdf";
break;
case 7:
format = "ofd";
break;
default:
break;
}
param.m_fileNameExt = format;
param.m_isOcr = (ui->cbox_format->currentIndex() >= 6);
param.m_isSaveAsMultiPage = ui->cbtn_multiFile->isChecked();
param.m_multiPagesType = (ui->radio_multiAll->isChecked()) ? 0 : 1;
@ -124,8 +131,8 @@ void Dialog_AquireInto::on_btn_option_clicked()
void Dialog_AquireInto::on_cbox_format_currentIndexChanged(int index)
{
ui->cbtn_multiFile->setEnabled(index > 2);
if (index < 3)
ui->cbtn_multiFile->setEnabled(index > 2 && index < 6);
if (index < 3 || index > 5)
ui->cbtn_multiFile->setChecked(false);
ui->btn_option->setEnabled(0 == index || 3 == index);

View File

@ -24,6 +24,7 @@ public:
int m_fileNameDigits;
int m_fileNameOddEventType;
QString m_fileNameExt;
bool m_isOcr;
bool m_isSaveAsMultiPage;
int m_multiPagesType;
int m_customMultiPages;

View File

@ -287,6 +287,16 @@
<property name="text">
<string>OFD - Open Fixed-layout Document(*.ofd)</string>
</property>
</item>
<item>
<property name="text">
<string>OCR->PDF - Portable Document Format(*.pdf)</string>
</property>
</item>
<item>
<property name="text">
<string>OCR->OFD - Open Fixed-layout Document(*.ofd)</string>
</property>
</item>
</widget>
</item>

View File

@ -26,7 +26,9 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
"PNG - Portable Network Graphics(*.png);;"
"TIF - TIFF Revision 6(*.tif);;"
"PDF - Portable Document Format(*.pdf);;"
"OFD - Open Fixed-layout Document(*.ofd)");
"OFD - Open Fixed-layout Document(*.ofd);;"
"OCR->PDF - Portable Document Format(*.pdf);;"
"OCR->OFD - Open Fixed-layout Document(*.ofd)");
connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted()));
connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close()));
@ -42,7 +44,7 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
m_suffix = getCfgValue("export", "suffix", 0);
ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix));
ui->check_saveAsMulti->setEnabled(m_suffix > 2);
ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6);
ui->check_saveAsMulti->setChecked(getCfgValue("export", "saveAsMulti", false));
ui->btn_option->setEnabled(0 == m_suffix || 3 == m_suffix);
@ -111,6 +113,11 @@ int Dialog_Export::getTiffQuality()
return getCfgValue("saveParam", "tiffQuality", 80);
}
bool Dialog_Export::isOcr()
{
return (m_suffix >= 6);
}
bool Dialog_Export::isSaveAsMultiPage()
{
return ui->check_saveAsMulti->isChecked();
@ -144,6 +151,12 @@ void Dialog_Export::on_dialog_accepted()
case 5:
extName = ".ofd";
break;
case 6:
extName = ".pdf";
break;
case 7:
extName = ".ofd";
break;
}
assert(!extName.isEmpty());
@ -183,8 +196,8 @@ void Dialog_Export::on_dialog_accepted()
void Dialog_Export::on_filterSelected(const QString& filterName)
{
m_suffix = ui->fileDialog->nameFilters().indexOf(filterName);
ui->check_saveAsMulti->setEnabled(m_suffix > 2);
if (m_suffix <= 2)
ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6);
if (m_suffix <= 2 || m_suffix >= 6)
ui->check_saveAsMulti->setChecked(false);
ui->btn_option->setEnabled(0 == m_suffix || 3 == m_suffix);

View File

@ -22,6 +22,7 @@ public:
int getTiffCompressionBW();
int getTiffCompression();
int getTiffQuality();
bool isOcr();
bool isSaveAsMultiPage();
void getSaveIndexs(std::vector<int> &indexs);

View File

@ -6,7 +6,7 @@
#include "../../utility/HGString.h"
Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destPath, const QString &destName, const QString &destExt,
bool isSaveAsMulti, int jpegQuality, int tiffCompressionBW, int tiffCompression, int tiffQuality,
bool isSaveAsMulti, int jpegQuality, int tiffCompressionBW, int tiffCompression, int tiffQuality, bool isOcr,
const QStringList &srcFiles, QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog_ExportImageFile)
@ -18,6 +18,7 @@ Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destPath, const QS
, m_tiffCompressionBW(tiffCompressionBW)
, m_tiffCompression(tiffCompression)
, m_tiffQuality(tiffQuality)
, m_isOcr(isOcr)
, m_srcFiles(srcFiles)
{
ui->setupUi(this);
@ -147,7 +148,7 @@ void Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param)
else if (2 == p->m_tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
saveInfo.tiffJpegQuality = (HGUInt)p->m_tiffQuality;
HGImgFmt_SaveImage(img, 0, &saveInfo, getStdString(saveFileName).c_str());
MainWindow::saveImage(img, &saveInfo, p->m_isOcr, getStdString(saveFileName).c_str());
HGBase_DestroyImage(img);
}
}

View File

@ -14,7 +14,7 @@ class Dialog_ExportImageFile : public QDialog
public:
explicit Dialog_ExportImageFile(const QString &destPath, const QString &destName, const QString &destExt,
bool isSaveAsMulti, int jpegQuality, int tiffCompressionBW, int tiffCompression, int tiffQuality,
bool isSaveAsMulti, int jpegQuality, int tiffCompressionBW, int tiffCompression, int tiffQuality, bool isOcr,
const QStringList &srcFiles, QWidget *parent = nullptr);
~Dialog_ExportImageFile();
@ -44,6 +44,7 @@ private:
int m_tiffCompressionBW;
int m_tiffCompression;
int m_tiffQuality;
bool m_isOcr;
QStringList m_srcFiles;
bool m_stopThread;

View File

@ -20,13 +20,19 @@ Dialog_SaveAs::Dialog_SaveAs(QWidget *parent) :
"PNG - Portable Network Graphics(*.png);;"
"TIF - TIFF Revision 6(*.tif);;"
"PDF - Portable Document Format(*.pdf);;"
"OFD - Open Fixed-layout Document(*.ofd)");
"OFD - Open Fixed-layout Document(*.ofd);;"
"OCR->PDF - Portable Document Format(*.pdf);;"
"OCR->OFD - Open Fixed-layout Document(*.ofd)");
connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted()));
connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close()));
connect(ui->fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(on_filterSelected(const QString&)));
m_suffix = getCfgValue("saveAs", "suffix", 0);
if (m_suffix > 7)
m_suffix = 7;
else if (m_suffix < 0)
m_suffix = 0;
ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix));
ui->btn_option->setEnabled(0 == m_suffix || 3 == m_suffix);
}
@ -61,6 +67,11 @@ int Dialog_SaveAs::getTiffQuality()
return getCfgValue("saveParam", "tiffQuality", 80);
}
bool Dialog_SaveAs::isOcr()
{
return (m_suffix >= 6);
}
void Dialog_SaveAs::on_dialog_accepted()
{
QString extName;
@ -84,6 +95,12 @@ void Dialog_SaveAs::on_dialog_accepted()
case 5:
extName = ".ofd";
break;
case 6:
extName = ".pdf";
break;
case 7:
extName = ".ofd";
break;
}
assert(!extName.isEmpty());

View File

@ -20,6 +20,7 @@ public:
int getTiffCompressionBW();
int getTiffCompression();
int getTiffQuality();
bool isOcr();
private slots:
void on_dialog_accepted();

View File

@ -34,6 +34,7 @@
#include "imgfmt/HGTiff.h"
#include "imgfmt/HGImgFmt.h"
#include "imgproc/HGImgProc.h"
#include "imgproc/HGOCR.h"
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
#include "../../utility/HGString.h"
@ -263,6 +264,26 @@ void MainWindow::exitFullScreen()
m_dlgFullScreen = nullptr;
}
HGResult MainWindow::saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool ocr, const HGChar *fileName)
{
if (!ocr)
{
return HGImgFmt_SaveImage(image, 0, info, fileName);
}
HGResult ret = HGBASE_ERR_FAIL;
// 忽略info
HGOCRMgr ocrMgr = nullptr;
HGImgProc_CreateOCRMgr(&ocrMgr);
if (nullptr != ocrMgr)
{
ret = HGImgProc_ImageOCRToFile(ocrMgr, image, 0, fileName);
HGImgProc_DestroyOCRMgr(ocrMgr);
}
return ret;
}
void MainWindow::on_act_90Left_triggered()
{
if (HGBASE_ERR_OK == m_view->rotateLeft())
@ -715,12 +736,7 @@ void MainWindow::on_new_image(void *img)
if (1 == m_scanType)
{
QString fileName = getCacheFileName();
HGImgFmtSaveInfo saveInfo;
saveInfo.jpegQuality = 80;
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
saveInfo.tiffJpegQuality = 80;
HGImgFmt_SaveImage(image, 0, &saveInfo, getStdString(fileName).c_str());
HGImgFmt_SaveImage(image, 0, nullptr, getStdString(fileName).c_str());
if (-1 == m_scanInsertPos)
{
@ -870,7 +886,8 @@ void MainWindow::on_new_image(void *img)
else if (2 == m_aquireIntoSaveParam.m_tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality;
HGImgFmt_SaveImage(image, 0, &saveInfo, getStdString(scanFileName).c_str());
bool isOcr = m_aquireIntoSaveParam.m_isOcr;
saveImage(image, &saveInfo, isOcr, getStdString(scanFileName).c_str());
m_thumb->addItem(scanFileName);
++m_aquireIntoSaveParam.m_fileNameStartIndex;
@ -1569,6 +1586,7 @@ void MainWindow::on_act_save_triggered()
int tiffCompressionBW = dlg.getTiffCompressionBW();
int tiffCompression = dlg.getTiffCompression();
int tiffQuality = dlg.getTiffQuality();
bool isOcr = dlg.isOcr();
HGImgFmtSaveInfo saveInfo;
saveInfo.jpegQuality = (HGUInt)jpegQuality;
@ -1578,7 +1596,7 @@ void MainWindow::on_act_save_triggered()
else if (2 == tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
saveInfo.tiffJpegQuality = (HGUInt)tiffQuality;
if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, &saveInfo, getStdString(savePath).c_str()))
if (HGBASE_ERR_OK == saveImage(img, &saveInfo, isOcr, getStdString(savePath).c_str()))
{
m_thumb->updateItem(m_currIndex, savePath);
m_currFilePath = savePath;
@ -1685,6 +1703,7 @@ void MainWindow::on_act_saveAs_triggered()
int tiffCompressionBW = dlg.getTiffCompressionBW();
int tiffCompression = dlg.getTiffCompression();
int tiffQuality = dlg.getTiffQuality();
bool isOcr = dlg.isOcr();
HGImgFmtSaveInfo saveInfo;
saveInfo.jpegQuality = (HGUInt)jpegQuality;
@ -1694,7 +1713,7 @@ void MainWindow::on_act_saveAs_triggered()
else if (2 == tiffCompression)
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
saveInfo.tiffJpegQuality = (HGUInt)tiffQuality;
if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, &saveInfo, getStdString(savePath).c_str()))
if (HGBASE_ERR_OK == saveImage(img, &saveInfo, isOcr, getStdString(savePath).c_str()))
{
}
@ -1752,9 +1771,10 @@ void MainWindow::on_act_Export_triggered()
int tiffCompressionBW = dlg.getTiffCompressionBW();
int tiffCompression = dlg.getTiffCompression();
int tiffQuality = dlg.getTiffQuality();
bool isOcr = dlg.isOcr();
Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality,
tiffCompressionBW, tiffCompression, tiffQuality, srcFiles, this);
tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this);
dlgExport.exec();
}
}

View File

@ -56,6 +56,7 @@ public:
virtual ~MainWindow() override;
void exitFullScreen();
static HGResult saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool ocr, const HGChar *fileName);
private slots:
void on_act_90Left_triggered();

View File

@ -1,4 +1,4 @@
#include "HGOCR.h"
#include "HGOCR.h"
#include "HGOCRBase.hpp"
#include "HGOCRHanvon.hpp"
#include "HGOCRRetImpl.hpp"

View File

@ -1,4 +1,4 @@
#ifndef __HGOCR_H__
#ifndef __HGOCR_H__
#define __HGOCR_H__
#include "../base/HGDef.h"
@ -20,44 +20,44 @@ HG_DECLARE_HANDLE(HGOCRRet);
/* OFD */
#define HGIMGPROC_OCROUTTYPE_OFD 5L
/* 未旋转 */
/* 未旋转 */
#define HGIMGPROC_OCRTEXTDIRECT_ORI 1L
/* 顺时针旋转了90度 */
/* 顺时针旋转了90度 */
#define HGIMGPROC_OCRTEXTDIRECT_RIGHT 2L
/* 逆时针旋转了90度 */
/* 逆时针旋转了90度 */
#define HGIMGPROC_OCRTEXTDIRECT_LEFT 3L
/* 旋转了180度 */
/* 旋转了180度 */
#define HGIMGPROC_OCRTEXTDIRECT_180 4L
/* 初始化OCR模块
/* 初始化OCR模块
*/
HGEXPORT HGResult HGAPI HGImgProc_CreateOCRMgr(HGOCRMgr *ocrMgr);
/* 反初始化OCR模块
/* 反初始化OCR模块
*/
HGEXPORT HGResult HGAPI HGImgProc_DestroyOCRMgr(HGOCRMgr ocrMgr);
/* 图像OCR
/* 图像OCR
*/
HGEXPORT HGResult HGAPI HGImgProc_ImageOCR(HGOCRMgr ocrMgr, HGImage image, HGOCRRet *ocrRet);
/* 销毁OCR结果
/* 销毁OCR结果
*/
HGEXPORT HGResult HGAPI HGImgProc_DestroyOCRRet(HGOCRRet ocrRet);
/* 获取OCR结果块数量
/* 获取OCR结果块数量
*/
HGEXPORT HGResult HGAPI HGImgProc_GetOCRRetBlockCount(HGOCRRet ocrRet, HGUInt *count);
/* 获取OCR结果块文本
/* 获取OCR结果块文本
*/
HGEXPORT HGResult HGAPI HGImgProc_GetOCRRetBlockText(HGOCRRet ocrRet, HGUInt index, const HGChar **text);
/* 图像OCR到文件
/* 图像OCR到文件
*/
HGEXPORT HGResult HGAPI HGImgProc_ImageOCRToFile(HGOCRMgr ocrMgr, HGImage image, HGUInt outType, const HGChar *outFileName);
/* 获取图像识别方向
/* 获取图像识别方向
*/
HGEXPORT HGResult HGAPI HGImgProc_ImageTextDirectOCR(HGOCRMgr ocrMgr, HGImage image, HGUInt *direct);

View File

@ -1,4 +1,4 @@
#include "HGOCRBase.hpp"
#include "HGOCRBase.hpp"
#include "HGOCR.h"
#include "../base/HGInc.h"

View File

@ -1,4 +1,4 @@
#ifndef __HGOCRBASE_H__
#ifndef __HGOCRBASE_H__
#define __HGOCRBASE_H__
#include "../base/HGDef.h"

View File

@ -1,4 +1,4 @@
#include "HGOCRHanvon.hpp"
#include "HGOCRHanvon.hpp"
#include "HGOCR.h"
#include "HGOCRRetImpl.hpp"
#include "HGOCRRetImpl.hpp"

View File

@ -1,4 +1,4 @@
#ifndef __HGOCRHANVON_HPP__
#ifndef __HGOCRHANVON_HPP__
#define __HGOCRHANVON_HPP__
#include "HGOCRBase.hpp"

View File

@ -1,4 +1,4 @@
#include "HGOCRRetImpl.hpp"
#include "HGOCRRetImpl.hpp"
HGOCRRetImpl::HGOCRRetImpl(const std::vector<std::string>& blockInfo)
{

View File

@ -1,4 +1,4 @@
#ifndef __HGOCRRETIMPL_HPP__
#ifndef __HGOCRRETIMPL_HPP__
#define __HGOCRRETIMPL_HPP__
#include "../base/HGDef.h"