123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #include "thresholdtool.h"
- ThresholdTool::ThresholdTool(QWidget *parent) : ToolInterface(parent), ui(new Ui::ThresholdTool)
- {
- ui->setupUi(this);
- ui->horizontalSlidermin->setMinimum(0);
- ui->horizontalSlidermin->setMaximum(255);
- ui->horizontalSlidermin->setSingleStep(1);
- ui->horizontalSlidermax->setMinimum(0);
- ui->horizontalSlidermax->setMaximum(255);
- ui->horizontalSlidermax->setSingleStep(1);
- ui->horizontalSlidermin->setValue(50);
- ui->horizontalSlidermax->setValue(200);
- ui->label2->setText("50");
- ui->label4->setText("200");
- }
- ThresholdTool::~ThresholdTool()
- {
- delete ui;
- }
- bool ThresholdTool::Serialized(QDataStream& ar, bool bIsOut)
- {
- int paranum;//参数数量
- if (bIsOut)//保存参数流程
- {
- paranum = 3;
- ar << paranum;//先保存参数数量
- ar << (int)1 << Min;
- ar << (int)2 << Max;
- ar << (int)3 << (bool)ui->checkBox->isChecked();
- }
- else//加载参数流程,参数加载顺序一定要跟保存顺序一致
- {
- bool bIsChecked;
-
- int para;
- ar >> paranum;//读取参数数量
- for (int i = 0; i < paranum; i++)
- {
- ar >> para;
- switch (para)
- {
- case 1: ar >> Min; break;
- case 2: ar >> Max; break;
- case 3: ar >> bIsChecked; break;
- default:
- {
- qWarning() << "Serialized(In) Error";
- return false;
- }
- break;
- }
- }
- {
- ui->checkBox->setChecked(bIsChecked);
- ui->horizontalSlidermin->setValue(Min);
- ui->horizontalSlidermax->setValue(Max);
- ui->label2->setText(QString::number(Min));
- ui->label4->setText(QString::number(Max));
- emit updateParameter(ShowParameter());
- }
- }
- return true;
- }
- QString ThresholdTool::ShowParameter()
- {
- QString str;
- Min = ui->horizontalSlidermin->value();
- Max = ui->horizontalSlidermax->value();
- str += QString::number(Min);
- str += ",";
- str += QString::number(Max);
- str += ",";
- if(ui->checkBox->isChecked())
- {
- str += "1";
- }
- else
- {
- str += "0";
- }
- return str;
- }
- int ThresholdTool::Execute()
- {
- int result = 1;
- Min = ui->horizontalSlidermin->value();
- Max = ui->horizontalSlidermax->value();
- try
- {
- if(Max > Min)
- {
- HTuple Channels;
- CountChannels(m_InImage, &Channels);
- if(Channels == 1)
- {
- HTuple hv_Width, hv_Height;
- HObject ho_Regions;
- Threshold(m_InImage, &ho_Regions, Min, Max);
- GetImageSize(m_InImage, &hv_Width, &hv_Height);
-
- if(ui->checkBox->isChecked())
- {
- Complement(ho_Regions, &ho_Regions);
- }
- RegionToBin(ho_Regions, &m_OutImage, 255, 0, hv_Width, hv_Height);
- }
- }
- }
- catch(...)
- {
- }
- return result;
- }
- void ThresholdTool::on_horizontalSlidermin_valueChanged(int value)
- {
- ui->label2->setText(QString::number(value));
- emit updateParameter(ShowParameter());
- }
- void ThresholdTool::on_horizontalSlidermax_valueChanged(int value)
- {
- ui->label4->setText(QString::number(value));
- emit updateParameter(ShowParameter());
- }
- void ThresholdTool::on_checkBox_clicked()
- {
- emit updateParameter(ShowParameter());
- }
|