HGGitLab

Commit 14bcbe7f authored by luoliangyi's avatar luoliangyi

1.app增加纠偏功能

2.imgproc库修改纠偏接口
parent 735ab83d
......@@ -57,6 +57,7 @@ SOURCES += \
dialog_fullscreen.cpp \
dialog_imageinfo.cpp \
dialog_imgproc_adjust.cpp \
dialog_imgproc_autocrop.cpp \
dialog_multirotate.cpp \
dialog_multirotateimagefile.cpp \
dialog_openimageindex.cpp \
......@@ -75,6 +76,7 @@ HEADERS += \
dialog_fullscreen.h \
dialog_imageinfo.h \
dialog_imgproc_adjust.h \
dialog_imgproc_autocrop.h \
dialog_multirotate.h \
dialog_multirotateimagefile.h \
dialog_openimageindex.h \
......@@ -91,6 +93,7 @@ FORMS += \
dialog_fullscreen.ui \
dialog_imageinfo.ui \
dialog_imgproc_adjust.ui \
dialog_imgproc_autocrop.ui \
dialog_multirotate.ui \
dialog_multirotateimagefile.ui \
dialog_openimageindex.ui \
......
#include "dialog_imgproc_autocrop.h"
#include "ui_dialog_imgproc_autocrop.h"
#include <QAbstractButton>
#include <QPushButton>
#include <QMouseEvent>
#include <QDebug>
Dialog_ImgProc_AutoCrop::Dialog_ImgProc_AutoCrop(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog_ImgProc_AutoCrop)
, m_example_flag(-1)
, m_btnGroup_polygon(this)
, m_btnGroup_backgroundColor(this)
, m_isCrop(false)
, m_isDeskew(false)
, m_isFillBlank(false)
, m_isConvex(false)
, m_isAutoColor(false)
, m_isUseAdvancedParam(false)
, m_threshold(40)
, m_noise(8)
, m_indent(5)
{
ui->setupUi(this);
m_btnGroup_polygon.addButton(ui->rbtn_convex);
m_btnGroup_polygon.addButton(ui->rbtn_concave);
m_btnGroup_backgroundColor.addButton(ui->rbtn_autoColor);
m_btnGroup_backgroundColor.addButton(ui->rbtn_defaultColor);
ui->cbtn_crop->setChecked(false);
ui->cbtn_corrSkew->setChecked(false);
ui->gbox_fillBlank->setChecked(false);
ui->rbtn_convex->setChecked(true);
ui->rbtn_autoColor->setChecked(true);
ui->gbox_param->setChecked(false);
ui->spin_threshold->setValue(40);
ui->spin_noise->setValue(8);
ui->spin_indent->setValue(5);
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage()));
ui->lab_arrow->setPixmap(QPixmap::fromImage(QImage()));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage()));
this->setMouseTracking(true);
}
Dialog_ImgProc_AutoCrop::~Dialog_ImgProc_AutoCrop()
{
delete ui;
}
void Dialog_ImgProc_AutoCrop::mouseMoveEvent(QMouseEvent *event)
{
QRect rect_cbtn_crop(ui->cbtn_crop->mapTo(this, QPoint(0, 0)), ui->cbtn_crop->size());
QRect rect_cbtn_corrSkew(ui->cbtn_corrSkew->mapTo(this, QPoint(0, 0)), ui->cbtn_corrSkew->size());
QRect rect_gbox_fillBlank(ui->gbox_fillBlank->mapTo(this, QPoint(0, 0)), ui->gbox_fillBlank->size());
QRect rect_rbtn_convex(ui->rbtn_convex->mapTo(this, QPoint(0, 0)), ui->rbtn_convex->size());
QRect rect_rbtn_concave(ui->rbtn_concave->mapTo(this, QPoint(0, 0)), ui->rbtn_concave->size());
QRect rect_rbtn_autoColor(ui->rbtn_autoColor->mapTo(this, QPoint(0, 0)), ui->rbtn_autoColor->size());
QRect rect_rbtn_defaultColor(ui->rbtn_defaultColor->mapTo(this, QPoint(0, 0)), ui->rbtn_defaultColor->size());
if (rect_cbtn_crop.contains(event->pos()) && m_example_flag != 0)
updateExample(0);
else if (rect_cbtn_corrSkew.contains(event->pos()) && m_example_flag != 1)
updateExample(1);
else if (rect_gbox_fillBlank.contains(event->pos()))
{
if(ui->gbox_fillBlank->isChecked())
{
if(rect_rbtn_convex.contains(event->pos()) && m_example_flag != 3)
updateExample(3);
else if(rect_rbtn_concave.contains(event->pos()) && m_example_flag != 4)
updateExample(4);
else if (rect_rbtn_autoColor.contains(event->pos()) && m_example_flag != 5)
updateExample(5);
else if (rect_rbtn_defaultColor.contains(event->pos()) && m_example_flag != 6)
updateExample(6);
else if(m_example_flag < 2 || m_example_flag > 6)
updateExample(2);
}
else if(m_example_flag != 2)
updateExample(2);
}
QDialog::mouseMoveEvent(event);
}
void Dialog_ImgProc_AutoCrop::on_buttonBox_clicked(QAbstractButton *button)
{
if(ui->buttonBox->standardButton(button) == QDialogButtonBox::RestoreDefaults)
{
ui->cbtn_crop->setChecked(false);
ui->cbtn_corrSkew->setChecked(false);
ui->gbox_fillBlank->setChecked(false);
ui->rbtn_convex->setChecked(true);
ui->rbtn_autoColor->setChecked(true);
ui->gbox_param->setChecked(false);
ui->spin_threshold->setValue(40);
ui->spin_noise->setValue(8);
ui->spin_indent->setValue(5);
}
}
void Dialog_ImgProc_AutoCrop::on_buttonBox_accepted()
{
m_isCrop = ui->cbtn_crop->isChecked();
m_isDeskew = ui->cbtn_corrSkew->isChecked();
m_isFillBlank = ui->gbox_fillBlank->isChecked();
m_isConvex = ui->rbtn_convex->isChecked();
m_isAutoColor = ui->rbtn_autoColor->isChecked();
m_isUseAdvancedParam = ui->gbox_param->isChecked();
m_threshold = ui->spin_threshold->value();
m_noise = ui->spin_noise->value();
m_indent = ui->spin_indent->value();
}
void Dialog_ImgProc_AutoCrop::updateExample(int example)
{
if(m_example_flag == -1)
ui->lab_arrow->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_arrow.png")));
m_example_flag = example;
switch (example) {
case 0:
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_black_before.png")));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_crop_after.png")));
break;
case 1:
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_deskew_before.png")));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_deskew_after.png")));
break;
case 2:
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_black_before.png")));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_black_after.png")));
break;
case 3:
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_before.png")));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_convex.png")));
break;
case 4:
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_before.png")));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_concave.png")));
break;
case 5:
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_before.png")));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_auto.png")));
break;
case 6:
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_before.png")));
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_default.png")));
break;
default:
break;
}
}
#ifndef DIALOG_IMGPROC_AUTOCROP_H
#define DIALOG_IMGPROC_AUTOCROP_H
#include <QDialog>
#include <QButtonGroup>
class QAbstractButton;
namespace Ui {
class Dialog_ImgProc_AutoCrop;
}
class Dialog_ImgProc_AutoCrop : public QDialog
{
Q_OBJECT
public:
explicit Dialog_ImgProc_AutoCrop(QWidget *parent = nullptr);
~Dialog_ImgProc_AutoCrop();
bool isCrop() {return m_isCrop;}
bool isDeskew() {return m_isDeskew;}
bool isFillBlank() {return m_isFillBlank;}
bool isConvex() {return m_isConvex;}
bool isAutoColor() {return m_isAutoColor;}
bool isUseAdvancedParam() {return m_isUseAdvancedParam;}
int getThreshold() {return m_threshold;}
int getNoise() {return m_noise;}
int getIndent() {return m_indent;}
protected:
void mouseMoveEvent(QMouseEvent *event);
private slots:
void on_buttonBox_clicked(QAbstractButton *button);
void on_buttonBox_accepted();
private:
void updateExample(int example);//example: 0 - autocrop; 1 - deskew; 2 - fillblack; 3 - fillblack_convex; 4 - fillblack_concave
private:
Ui::Dialog_ImgProc_AutoCrop *ui;
int m_example_flag;
QButtonGroup m_btnGroup_polygon;
QButtonGroup m_btnGroup_backgroundColor;
bool m_isCrop;
bool m_isDeskew;
bool m_isFillBlank;
bool m_isConvex;
bool m_isAutoColor;
bool m_isUseAdvancedParam;
int m_threshold;
int m_noise;
int m_indent;
};
#endif // DIALOG_IMGPROC_AUTOCROP_H
This diff is collapsed.
......@@ -13,8 +13,10 @@
#include "dialog_imgproc_adjust.h"
#include "dialog_multirotate.h"
#include "dialog_multirotateimagefile.h"
#include "dialog_imgproc_autocrop.h"
#include "imgfmt/HGPdf.h"
#include "imgfmt/HGImgFmt.h"
#include "imgproc/HGImgProc.h"
#include "HGUIGlobal.h"
MainWindow::MainWindow(QWidget *parent)
......@@ -587,6 +589,7 @@ void MainWindow::updateActionStatus()
ui->act_adjust->setEnabled(nullptr != img);
ui->act_multiRotate->setEnabled(0 != count);
ui->menu_Rotate->setEnabled(0 != count || nullptr != img);
ui->act_autoCrop->setEnabled(nullptr != img);
}
void MainWindow::on_act_openPageNum_triggered()
......@@ -721,6 +724,7 @@ void MainWindow::on_act_adjust_triggered()
{
m_view->addImage(dlg.getAfterImage());
m_modify = true;
updateActionStatus();
}
else
{
......@@ -780,6 +784,7 @@ void MainWindow::on_act_closeFile_triggered()
else
{
m_modify = false;
updateActionStatus();
}
}
}
......@@ -809,6 +814,7 @@ void MainWindow::on_act_closeAll_triggered()
else
{
m_modify = false;
updateActionStatus();
}
}
......@@ -834,7 +840,7 @@ void MainWindow::on_act_save_triggered()
{
m_thumb->refreshItem(m_currFilePath);
m_modify = false;
//QMessageBox::information(this, "info", "save ok");
updateActionStatus();
}
else
{
......@@ -1143,5 +1149,47 @@ void MainWindow::on_act_multiRotate_triggered()
void MainWindow::on_act_autoCrop_triggered()
{
HGImage img = nullptr;
m_view->getImage(&img);
if (nullptr == img)
{
return;
}
Dialog_ImgProc_AutoCrop dlg(this);
if (dlg.exec())
{
bool isCrop = dlg.isCrop();
bool isDeskew = dlg.isDeskew();
bool isFillBlank = dlg.isFillBlank();
bool isConvex = dlg.isConvex();
bool isAutoColor = dlg.isAutoColor();
int threshold = dlg.getThreshold();
int noise = dlg.getNoise();
int indent = dlg.getIndent();
HGImgDeskewParam deskewParam;
deskewParam.fillBlank = (HGBool)isFillBlank;
deskewParam.convex = (HGBool)isConvex;
deskewParam.colorBlank = (HGBool)isAutoColor;
deskewParam.useParam = HGTRUE;
deskewParam.threshold = threshold;
deskewParam.noise = noise;
deskewParam.indent = indent;
HGImageInfo imgInfo;
HGBase_GetImageInfo(img, &imgInfo);
HGImage destImage = nullptr;
HGImgProc_ImageDeskew(img, (HGBool)isCrop, (HGBool)isDeskew, &deskewParam, imgInfo.width, imgInfo.height,
HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &destImage);
if (nullptr != destImage)
{
m_view->addImage(destImage);
HGBase_DestroyImage(destImage);
m_modify = true;
updateActionStatus();
}
}
}
......@@ -181,7 +181,7 @@
<set>QDockWidget::NoDockWidgetFeatures</set>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
<number>1</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<property name="minimumSize">
......
......@@ -120,7 +120,7 @@ BOOL CHGTestDlg::OnInitDialog()
HGImgFmt_LoadImage("D:\\1.bmp", 0, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_BOTTOM, &img);
HGImage imgCrop = NULL;
HGImgProc_ImageDeskew(img, HGFALSE, HGFALSE, HGFALSE, NULL, 800, 1200, HGBASE_IMGTYPE_BGRA, HGBASE_IMGORIGIN_TOP, &imgCrop);
HGImgProc_ImageDeskew(img, HGFALSE, HGFALSE, NULL, 800, 1200, HGBASE_IMGTYPE_BGRA, HGBASE_IMGORIGIN_TOP, &imgCrop);
HGImgFmt_SaveImage(imgCrop, 0, NULL, 0, "D:\\deskew.bmp");
HGBase_DestroyImage(imgCrop);
HGBase_DestroyImage(img);
......
......@@ -183,7 +183,7 @@ HGResult HGAPI HGImgProc_ImageAdjustColors(HGImage image, HGImage destImage,
return HGBASE_ERR_OK;
}
HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool deskew, HGBool fillBlank, const HGImgDeskewParam* param,
HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool deskew, const HGImgDeskewParam* param,
HGUInt destWidth, HGUInt destHeight, HGUInt destType, HGUInt destOrigin, HGImage* destImage)
{
if (NULL == image || NULL == destImage)
......@@ -198,6 +198,7 @@ HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool desk
return HGBASE_ERR_INVALIDDATA;
}
bool fillBlank = false;
bool convex = true;
bool colorBlank = false;
double threshold = 40.0;
......@@ -206,11 +207,19 @@ HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool desk
if (NULL != param)
{
convex = param->convex;
colorBlank = param->colorBlank;
threshold = param->threshold;
noise = param->noise;
indent = param->indent;
if (param->fillBlank)
{
fillBlank = true;
convex = (bool)param->convex;
colorBlank = (bool)param->colorBlank;
}
if (param->useParam)
{
threshold = param->threshold;
noise = param->noise;
indent = param->indent;
}
}
HGByte* data = NULL;
......
......@@ -14,8 +14,12 @@
/* 纠偏参数 */
typedef struct
{
/* 填充 */
HGBool fillBlank;
HGBool convex;
HGBool colorBlank;
/* 其他参数 */
HGBool useParam;
HGDouble threshold;
HGInt noise;
HGInt indent;
......@@ -55,18 +59,17 @@ HGEXPORT HGResult HGAPI HGImgProc_ImageAdjustColors(HGImage image, HGImage destI
* 1) image: in, 图像句柄
* 2) autoCrop: in, 是否自动裁剪, 为HGTRUE则忽略destWidth和destHeight
* 3) deskew: in, 是否纠偏
* 4) fillBlank: in, 是否进行背景填充
* 5) param: in, 纠偏参数, 为NULL时使用默认参数
* 6) destWidth: in, 目标图像宽度
* 7) destHeight: in, 目标图像高度
* 8) destType: in, 目标图像类型
* 9) destOrigin: in, 目标图像数据排列方式
* 10) destImage: out, 输出的目标图像句柄
* 4) param: in, 纠偏参数, 为NULL时使用默认参数
* 5) destWidth: in, 目标图像宽度
* 6) destHeight: in, 目标图像高度
* 7) destType: in, 目标图像类型
* 8) destOrigin: in, 目标图像数据排列方式
* 9) destImage: out, 输出的目标图像句柄
* * 说明:
* 1) 操作的只是image的ROI区域
* 2) 目前只支持image的类型为HGBASE_IMGTYPE_GRAY和HGBASE_IMGTYPE_RGB
*/
HGEXPORT HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool deskew, HGBool fillBlank, const HGImgDeskewParam* param,
HGEXPORT HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool deskew, const HGImgDeskewParam* param,
HGUInt destWidth, HGUInt destHeight, HGUInt destType, HGUInt destOrigin, HGImage* destImage);
#endif /* __HGIMGPROC_H__ */
\ No newline at end of file
......@@ -14,8 +14,12 @@
/* 纠偏参数 */
typedef struct
{
/* 填充 */
HGBool fillBlank;
HGBool convex;
HGBool colorBlank;
/* 其他参数 */
HGBool useParam;
HGDouble threshold;
HGInt noise;
HGInt indent;
......@@ -55,18 +59,17 @@ HGEXPORT HGResult HGAPI HGImgProc_ImageAdjustColors(HGImage image, HGImage destI
* 1) image: in, 图像句柄
* 2) autoCrop: in, 是否自动裁剪, 为HGTRUE则忽略destWidth和destHeight
* 3) deskew: in, 是否纠偏
* 4) fillBlank: in, 是否进行背景填充
* 5) param: in, 纠偏参数, 为NULL时使用默认参数
* 6) destWidth: in, 目标图像宽度
* 7) destHeight: in, 目标图像高度
* 8) destType: in, 目标图像类型
* 9) destOrigin: in, 目标图像数据排列方式
* 10) destImage: out, 输出的目标图像句柄
* 4) param: in, 纠偏参数, 为NULL时使用默认参数
* 5) destWidth: in, 目标图像宽度
* 6) destHeight: in, 目标图像高度
* 7) destType: in, 目标图像类型
* 8) destOrigin: in, 目标图像数据排列方式
* 9) destImage: out, 输出的目标图像句柄
* * 说明:
* 1) 操作的只是image的ROI区域
* 2) 目前只支持image的类型为HGBASE_IMGTYPE_GRAY和HGBASE_IMGTYPE_RGB
*/
HGEXPORT HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool deskew, HGBool fillBlank, const HGImgDeskewParam* param,
HGEXPORT HGResult HGAPI HGImgProc_ImageDeskew(HGImage image, HGBool autoCrop, HGBool deskew, const HGImgDeskewParam* param,
HGUInt destWidth, HGUInt destHeight, HGUInt destType, HGUInt destOrigin, HGImage* destImage);
#endif /* __HGIMGPROC_H__ */
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment