Compare commits

..

3 Commits

6 changed files with 488 additions and 602 deletions

View File

@ -166,59 +166,64 @@ void Form_mainInterface::checkDynamicCorrectItem(bool pass, int correctType)
type = 5;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI)
type = 6;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI)
type = 7;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI)
type = 8;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI)
type = 9;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI)
type = 10;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI)
type = 11;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI)
type = 12;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI)
type = 13;
else if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI)
type = 14;
bool allPass = false;
int correctItemId = -1;
bool correct_3399 = false;
for (int i = 0; i < ui->tableWidget->rowCount(); i++)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (item != nullptr)
{
if (item == nullptr)
break;
QString title = item->text();
QString name = m_map_title_name.value(title).name;
if (HGPDTTOOLDB_NAME_IMAGE_CORRECTION == name)
if (HGPDTTOOLDB_NAME_IMAGE_CORRECTION == name || HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399 == name)
{
if (HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399 == name)
correct_3399 = true;
correctItemId = i;
}
if (1 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_200DPI == name)
{
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(i, 2)->setBackgroundColor(pass ? QColor(0,255,0) : QColor(255,0,0));
ui->tableWidget->item(i, 2)->setText(pass ? tr("pass") : tr("not pass"));
}
else if (2 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_200DPI == name)
{
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(i, 2)->setBackgroundColor(pass ? QColor(0,255,0) : QColor(255,0,0));
ui->tableWidget->item(i, 2)->setText(pass ? tr("pass") : tr("not pass"));
}
else if (3 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI == name)
{
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(i, 2)->setBackgroundColor(pass ? QColor(0,255,0) : QColor(255,0,0));
ui->tableWidget->item(i, 2)->setText(pass ? tr("pass") : tr("not pass"));
}
else if (4 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI == name)
{
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(i, 2)->setBackgroundColor(pass ? QColor(0,255,0) : QColor(255,0,0));
ui->tableWidget->item(i, 2)->setText(pass ? tr("pass") : tr("not pass"));
}
else if (5 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI == name)
{
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(i, 2)->setBackgroundColor(pass ? QColor(0,255,0) : QColor(255,0,0));
ui->tableWidget->item(i, 2)->setText(pass ? tr("pass") : tr("not pass"));
}
else if (6 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI == name)
if (1 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_200DPI == name ||
2 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_200DPI == name ||
3 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI == name ||
4 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI == name ||
5 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI == name ||
6 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI == name ||
7 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI == name ||
8 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI == name ||
9 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI == name ||
10 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI == name ||
11 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI == name ||
12 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI == name ||
13 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI == name ||
14 == type && HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI == name
)
{
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(i, 2)->setBackgroundColor(pass ? QColor(0,255,0) : QColor(255,0,0));
ui->tableWidget->item(i, 2)->setText(pass ? tr("pass") : tr("not pass"));
allPass = true;
if (!correct_3399)
{
int row = item->row();
ui->tableWidget->selectRow(row + 1);
@ -249,7 +254,17 @@ void Form_mainInterface::resetCorrectItems()
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI == name)
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399 == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI == name ||
HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI == name
)
{
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(i, 2)->setBackground(Qt::transparent);
@ -1068,7 +1083,7 @@ void Form_mainInterface::on_pbtn_start_clicked()
QString title = item->text();
QString name = m_map_title_name.value(title).name;
if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION)
if (name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION || name == HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399)
{
resetCorrectItems();
}
@ -1088,7 +1103,7 @@ void Form_mainInterface::on_pbtn_start_clicked()
else if (title.contains("600dpi")) // == "扫描图像彩色质量确认_600dpi" || title == "扫描图像灰度质量确认_600dpi" || title == "计算畸变修正值_600dpi" || title == "设置畸变修正值_600dpi")
dpi = 600;
wchar_t buf[128] = {0};
wchar_t buf[512] = {0};
if (dpi > 0)
{
m_curDpi = dpi;

View File

@ -1,508 +0,0 @@
#include "correctProcess.h"
#include <opencv2/core/types_c.h>
#include <opencv2/core/core_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include <iostream>
#include <fstream>
bool getMeanColors(const cv::Mat& image, std::vector<std::vector<uchar>>& colors)
{
std::vector<std::vector<int>> sections;
cv::Mat resizeMat(image.rows, 2, CV_8UC1);
cv::resize(image(cv::Rect(0, 0, 10, image.rows)), resizeMat(cv::Rect(0, 0, 1, image.rows)), cv::Size(1, image.rows));
cv::resize(image(cv::Rect(image.cols - 11, 0, 10, image.rows)), resizeMat(cv::Rect(1, 0, 1, image.rows)), cv::Size(1, image.rows));
for (int i = 0; i < resizeMat.cols; i++)
{
cv::Mat col = resizeMat(cv::Rect(i, 0, 1, resizeMat.rows)).clone();
std::vector<int> section;
uchar* ptr = col.data;
int thre = 55;
for (int j = 2, rows = col.rows - 2; j < rows; j++)
{
if (abs(ptr[j - 2] - ptr[j + 2]) > thre)
{
if (section.size() > 1)
{
if (j - *(section.end() - 1) < 15)
continue;
}
else if (section.size() == 1)
if (j - section[0] < 50)
continue;
section.push_back(j);
j += 5;
}
}
if (section.size() < 53)
return false;
section.erase(section.begin());
sections.push_back(section);
}
std::vector<double> steps;
for (int i = 0, length = 52; i < length; i++)
steps.push_back(static_cast<double>(sections[1][i] - sections[0][i]) / (image.cols - 1));
for (int i = 0; i < image.cols; i++)
{
cv::Mat col = image(cv::Rect(i, 0, 1, image.rows)).clone();
std::vector<uchar> section_color;
for (size_t j = 0; j < 52; j += 2)
{
int top = sections[0][j] + i * steps[j] + 5;
int bottom = sections[0][j + 1] + i * steps[j + 1] - 5;
if (bottom <= top)
return false;
section_color.push_back(cv::mean(col(cv::Rect(0, top, 1, bottom - top + 1)))[0]);
}
for (size_t j = 1; j < section_color.size() - 1; j++)
if (section_color[j] < section_color[j - 1] || section_color[j] > section_color[j + 1])
section_color[j] = (int)(section_color[j - 1] + section_color[j + 1]) / 2;
colors.push_back(section_color);
}
return true;
}
bool calTable(const cv::Mat& image, uchar* lut_data, int blackLevel, char* data)
{
std::vector<std::vector<uchar>> colors;
if (!getMeanColors(image, colors))
return false;
int level = blackLevel;
#if 1
int index = 0;
for (size_t i = 0; i < colors.size(); i++)
for (size_t j = 0, length = colors[i].size(); j < length; j++)
{
data[index] = colors[i][j];
index++;
}
#endif
for (int i = 0; i < colors.size(); i++)
for (int j = 0; j < level; j++)
colors[i].erase(colors[i].begin());
double ss = 250.0 / (colors[0].size() - 1);
for (int i = 0, length = image.cols; i < length; i++)
{
uchar* ptr = lut_data + 256 * i;
memset(ptr, 255, 256);
memset(ptr, 0, 100);
for (int y = 1; y < colors[i].size(); y++)
{
int index_0 = colors[i][y - 1];
int index_1 = colors[i][y];
double value_0 = (y - 1) * ss;
double value_1 = cv::min(y * ss, 255.0);
double step = (double)(value_1 - value_0) / (double)(index_1 - index_0);
for (int x = index_0; x < index_1; x++)
ptr[x] = cv::min((int)(value_0 + (x - index_0) * step), 255);
}
}
return true;
}
cv::Mat createTable(const cv::Mat& image, int blackLevel, char* data)
{
cv::Mat grey(image.rows, image.cols * image.channels(), CV_8UC1, image.data);
cv::Mat lut_data(grey.cols, 256, CV_8UC1);
if (!calTable(grey, lut_data.data, blackLevel, data))
return cv::Mat();
const int channels = (lut_data.rows % 408 == 0) ? 408 : 432;
for (size_t i = 0, block = lut_data.rows / channels; i < block; i++)
{
cv::Mat lutROI = lut_data(cv::Rect(0, i * channels, 256, channels));
cv::Mat tran;
cv::transpose(lutROI, tran);
memcpy(lutROI.data, tran.data, tran.total());
}
return lut_data;
}
int mean(const cv::Mat& image, const cv::Mat& mask)
{
cv::Mat mask1, mask2;
cv::threshold(image, mask1, 127, 255, cv::THRESH_BINARY);
mask2 = (~mask1) & mask;
mask1 &= mask;
double num1 = cv::sum(mask1)[0] / 255;
double num2 = cv::sum(mask2)[0] / 255;
double sum1 = cv::sum(mask1 & image)[0];
double sum2 = cv::sum(mask2 & image)[0];
if (num1 == 0 && num2 == 0)
return 0;
else if (num1 == 0 && num2 != 0)
return sum2 / num2;
else if (num1 != 0 && num2 == 0)
return sum1 / num1;
else if (abs(sum1 / num1 - sum2 / sum2) < 200)
return (sum1 + sum2) / (num1 + num2);
else
return (sum1 + sum2 + num2 * 255) / (num1 + num2);
}
void myFindContours(const cv::Mat& src, std::vector<std::vector<cv::Point>>& contours, std::vector<cv::Vec4i>& hierarchy, int retr, int method, cv::Point offset)
{
CvMat c_image = cvMat(src);
cv::MemStorage storage(cvCreateMemStorage());
CvSeq* _ccontours = 0;
cvFindContours(&c_image, storage, &_ccontours, sizeof(CvContour), retr, method, cvPoint(offset.x, offset.y));
if (!_ccontours)
{
contours.clear();
return;
}
cv::Seq<CvSeq*> all_contours(cvTreeToNodeSeq(_ccontours, sizeof(CvSeq), storage));
int total = (int)all_contours.size();
contours.resize(total);
cv::SeqIterator<CvSeq*> it = all_contours.begin();
for (int i = 0; i < total; i++, ++it)
{
CvSeq* c = *it;
((CvContour*)c)->color = (int)i;
int count = (int)c->total;
int* data = new int[count * 2];
cvCvtSeqToArray(c, data);
for (int j = 0; j < count; j++)
{
contours[i].push_back(cv::Point(data[j * 2], data[j * 2 + 1]));
}
delete[] data;
}
hierarchy.resize(total);
it = all_contours.begin();
for (int i = 0; i < total; i++, ++it)
{
CvSeq* c = *it;
int h_next = c->h_next ? ((CvContour*)c->h_next)->color : -1;
int h_prev = c->h_prev ? ((CvContour*)c->h_prev)->color : -1;
int v_next = c->v_next ? ((CvContour*)c->v_next)->color : -1;
int v_prev = c->v_prev ? ((CvContour*)c->v_prev)->color : -1;
hierarchy[i] = cv::Vec4i(h_next, h_prev, v_next, v_prev);
}
storage.release();
}
void myFillPolys(cv::Mat& image, const std::vector<std::vector<cv::Point>>& contours, const cv::Scalar& color)
{
if (contours.empty()) return;
size_t count = contours.size();
cv::Point** pointss = new cv::Point * [count];
int* npts = new int[count];
for (size_t i = 0; i < count; i++)
{
size_t length = contours[i].size();
npts[i] = length;
pointss[i] = new cv::Point[length];
for (size_t j = 0; j < length; j++)
pointss[i][j] = contours[i][j];
}
cv::fillPoly(image, const_cast<const cv::Point**>(pointss), npts, count, color);
for (size_t i = 0; i < count; i++)
delete[] pointss[i];
delete[] pointss;
delete[] npts;
}
void createTable(const std::vector<double>& points_x, const std::vector<uchar>& points_y, uchar* table)
{
int table_temp[256]{};
for (size_t i = 0; i < points_x.size(); i++)
{
int current_index = static_cast<int>(points_x[i]);
if (current_index == 255)
current_index = 0;
if (current_index < 0)
current_index += 255;
int next_index = static_cast<int>(points_x[(i + 1) % points_x.size()]);
double low = points_y[i];
double up = points_y[(i + 1) % points_y.size()];
if (low == 255)
low = 0;
if (up < low)
up += 255;
if (next_index < current_index)
next_index += 256;
int length = next_index - current_index + 1;
double step = (up - low) / length;
for (int j = 0; j < length; j++)
table_temp[(j + current_index) % 256] = step * j + low;
for (size_t j = 0; j < 256; j++)
table[j] = table_temp[j] % 255;
}
}
cv::Mat createColorCastTable(const cv::Mat& image, const std::vector<uchar>& points_y)
{
cv::Mat resizeMat;
cv::resize(image, resizeMat, cv::Size(800, 800));
cv::Mat hsv, mv[3];
cv::cvtColor(resizeMat, hsv, cv::COLOR_BGR2HSV_FULL);
cv::split(hsv, mv);
cv::threshold(mv[1], mv[1], 80, 255, cv::THRESH_BINARY);
cv::threshold(mv[2], mv[2], 30, 255, cv::THRESH_BINARY);
cv::Mat mask = mv[1] & mv[2];
cv::erode(mask, mask, cv::Mat());
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
myFindContours(mask, contours, hierarchy, 0, 2, cv::Point(-1, -1));
for (std::vector<std::vector<cv::Point>>::iterator iter = contours.begin(); iter != contours.end();)
if (cv::contourArea(*iter) < 400)
iter = contours.erase(iter);
else
iter++;
if (contours.size() < 12)
return cv::Mat();
for (size_t i = 0; i < contours.size() - 1; i++)
for (size_t j = i + 1; j < contours.size(); j++)
if (contours[j][0].x < contours[i][0].x)
std::swap(contours[j], contours[i]);
std::vector<double> points_x;
std::vector<std::vector<cv::Point>> contours_temp;
for (size_t i = 0; i < 12; i++)
{
contours_temp.clear();
contours_temp.push_back(contours[i]);
mask = cv::Mat::zeros(resizeMat.size(), CV_8UC1);
myFillPolys(mask, contours_temp, cv::Scalar::all(255));
int mean_value = mean(mv[0], mask);
if (mean_value >= 255)
mean_value -= 255;
points_x.push_back(mean_value);
}
if (points_x[0] + points_x[1] + points_x[2] > points_x[8] + points_x[9] + points_x[10])
std::reverse(points_x.begin(), points_x.end());
cv::Mat table(256, 1, CV_8UC1);
createTable(points_x, points_y, table.data);
return table;
}
void correctLUT(cv::Mat& image, const cv::Mat& lut)
{
cv::Mat image_temp(image.rows, image.step / lut.channels(), CV_8UC(lut.channels()), image.data);
for (size_t i = 0; i < image_temp.cols; i++)
cv::LUT(image_temp(cv::Rect(i, 0, 1, image_temp.rows)), lut(cv::Rect(0, i, 256, 1)), image_temp(cv::Rect(i, 0, 1, image_temp.rows)));
}
std::vector<cv::Mat> correctProcess(cv::Mat& image, int blackLevel, bool colorCastEnable, const std::vector<uchar>& referValues, int dpi, const std::string& path)
{
std::vector<cv::Mat> ret;
if (image.empty())
return ret;
char* data = new char[image.step * 26];
cv::Mat lut1 = createTable(image(cv::Rect(0, 0, image.cols / 2, image.rows)).clone(), blackLevel, data);
if (lut1.empty())
{
delete[] data;
return ret;
}
cv::Mat lut2 = createTable(image(cv::Rect(image.cols / 2, 0, image.cols / 2, image.rows)).clone(), blackLevel, data + image.step * 13);
if (lut2.empty())
{
delete[] data;
return ret;
}
std::ofstream file;
file.open(path + std::to_string(dpi) + (image.channels() == 3 ? "c" : "g") + ".dat", std::ios::binary | std::ios::out);
file.write(data, image.step * 26);
file.close();
delete[] data;
cv::Mat lut(lut1.rows + lut2.rows, 256, CV_8UC1);
lut1.copyTo(lut(cv::Rect(0, 0, 256, lut1.rows)));
lut2.copyTo(lut(cv::Rect(0, lut1.rows, 256, lut2.rows)));
ret.push_back(lut);
if (!blackLevel || image.channels() == 1)
return ret;
int channel = (lut.rows % 408 == 0) ? 408 : 432;
cv::Mat lutMat(lut.rows / channel, 256, CV_8UC(channel), lut.data);
correctLUT(image, lutMat);
cv::Mat colorCastTable = createColorCastTable(image(cv::Rect(0, 0, image.cols / 2, image.rows)), referValues);
ret.push_back(colorCastTable);
if (!colorCastTable.empty())
{
file.open(path + "cc" + std::to_string(dpi) + "f.dat", std::ios::binary | std::ios::out);
file.write((char*)colorCastTable.data, 256);
file.close();
}
colorCastTable = createColorCastTable(image(cv::Rect(image.cols / 2, 0, image.cols / 2, image.rows)), referValues);
ret.push_back(colorCastTable);
if (!colorCastTable.empty())
{
file.open(path + "cc" + std::to_string(dpi) + "b.dat", std::ios::binary | std::ios::out);
file.write((char*)colorCastTable.data, 256);
file.close();
}
return ret;
}
std::vector<cv::Mat> correctProcess(cv::Mat& image1, cv::Mat& image2, int blackLevel, bool colorCastEnable, const std::vector<uchar>& referValues, int dpi, const std::string& path)
{
std::vector<cv::Mat> ret;
char* data = new char[(image1.step + image2.step) * 26];
cv::Mat lut1 = createTable(image1, blackLevel, data);
if (lut1.empty())
return ret;
cv::Mat lut2 = createTable(image2, blackLevel, data);
if (lut2.empty())
return ret;
std::ofstream file;
file.open(path + std::to_string(dpi) + (image1.channels() == 3 ? "c" : "g") + ".dat", std::ios::binary | std::ios::out);
file.write(data, (image1.step + image2.step) * 26);
file.close();
delete[] data;
cv::Mat lut(lut1.rows + lut2.rows, 256, CV_8UC1);
lut1.copyTo(lut(cv::Rect(0, 0, 256, lut1.rows)));
lut2.copyTo(lut(cv::Rect(0, lut1.rows, 256, lut2.rows)));
ret.push_back(lut);
if (!blackLevel || image1.channels() == 1 || image2.channels() == 1)
return ret;
cv::Mat image(cv::max(image1.rows, image2.rows), image1.cols + image2.cols, CV_8UC3);
image1.copyTo(image(cv::Rect(0, 0, image1.cols, image1.rows)));
image2.copyTo(image(cv::Rect(image1.cols, 0, image2.cols, image2.rows)));
int channel = (lut.rows % 408 == 0) ? 408 : 432;
cv::Mat lutMat(lut.rows / channel, 256, CV_8UC(channel), lut.data);
correctLUT(image, lutMat);
cv::Mat colorCastTable = createColorCastTable(image(cv::Rect(0, 0, image.cols / 2, image.rows)), referValues);
ret.push_back(colorCastTable);
if (!colorCastTable.empty())
{
file.open(path + "cc" + std::to_string(dpi) + "f.dat", std::ios::binary | std::ios::out);
file.write((char*)colorCastTable.data, 256);
file.close();
}
colorCastTable = createColorCastTable(image(cv::Rect(image.cols / 2, 0, image.cols / 2, image.rows)), referValues);
ret.push_back(colorCastTable);
if (!colorCastTable.empty())
{
file.open(path + "cc" + std::to_string(dpi) + "b.dat", std::ios::binary | std::ios::out);
file.write((char*)colorCastTable.data, 256);
file.close();
}
return ret;
}
cv::Mat readZipCorrect(uchar* data, int len, int blackLevel)
{
std::vector<std::vector<uchar>> colors;
int index = 0, cols = len / 26;
cv::Mat lut(cols, 256, CV_8UC1);
for (size_t i = 0; i < cols; i++)
{
std::vector<uchar> color;
for (size_t j = 0; j < 26; j++, index++)
color.push_back(data[index]);
colors.push_back(color);
}
for (int i = 0; i < colors.size(); i++)
for (int j = 0; j < blackLevel; j++)
colors[i].erase(colors[i].begin());
double ss = 250.0 / (colors[0].size() - 1);
for (int i = 0; i < cols; i++)
{
uchar* ptr = lut.data + 256 * i;
memset(ptr, 255, 256);
memset(ptr, 0, 100);
for (int y = 1; y < colors[i].size(); y++)
{
int index_0 = colors[i][y - 1];
int index_1 = colors[i][y];
double value_0 = (y - 1) * ss;
double value_1 = cv::min(y * ss, 255.0);
double step = (double)(value_1 - value_0) / (double)(index_1 - index_0);
for (int x = index_0; x < index_1; x++)
ptr[x] = cv::min((int)(value_0 + (x - index_0) * step), 255);
}
}
const int channels = (lut.rows % 408 == 0) ? 408 : 432;
for (size_t i = 0, block = lut.rows / channels; i < block; i++)
{
cv::Mat lutROI = lut(cv::Rect(0, i * channels, 256, channels));
cv::Mat tran;
cv::transpose(lutROI, tran);
memcpy(lutROI.data, tran.data, tran.total());
}
cv::Mat lutMat(lut.rows / channels, 256, CV_8UC(channels));
memcpy(lutMat.data, lut.data, lut.total());
return lutMat;
}

View File

@ -1,35 +0,0 @@
#ifndef CORRECT_PROCESS_H
#define CORRECT_PROCESS_H
#include <opencv2/opencv.hpp>
//uchar m_byteArray[78336 * 26];
//int m_index[] = { 0, 4896 * 26 * 3, 4896 * 26 * 4, 4896 * 26 * 7, 4896 * 26 * 8, (78336 - 9796 * 4) * 26, (78336 - 9796) * 26 };
/// <summary>
/// 校正处理。灰阶校正+色偏校正。
/// </summary>
/// <param name="image">灰阶校正原图</param>
/// <param name="blackLevel">黑色等级</param>
/// <param name="colorCastEnable">色偏校正使能。true为进行色偏校正false为禁止</param>
/// <param name="referValues">色偏校正参考数据</param>
/// <param name="path">校正数据关键点文件保存路径</param>
/// <returns>[0]为灰阶校正数据;[1]为正面色偏校正数据;[2]为反面校正数据</returns>
std::vector<cv::Mat> correctProcess(cv::Mat& image, int blackLevel, bool colorCastEnable, const std::vector<uchar>& referValues, int dpi, const std::string& path);
/// <summary>
/// 校正处理。灰阶校正+色偏校正。
/// </summary>
/// <param name="image1">灰阶校正原图(正)</param>
/// <param name="image2">灰阶校正原图(反)</param>
/// <param name="blackLevel">黑色等级</param>
/// <param name="colorCastEnable">色偏校正使能。true为进行色偏校正false为禁止</param>
/// <param name="referValues">色偏校正参考数据</param>
/// <param name="path">校正数据关键点文件保存路径</param>
/// <returns>[0]为灰阶校正数据;[1]为正面色偏校正数据;[2]为反面校正数据</returns>
std::vector<cv::Mat> correctProcess(cv::Mat& image1, cv::Mat& image2, int blackLevel, bool colorCastEnable, const std::vector<uchar>& referValues, int dpi, const std::string& path);
void correctLUT(cv::Mat& image, const cv::Mat& lut);
cv::Mat readZipCorrect(uchar* data, int len, int blackLevel);
#endif

View File

@ -139,6 +139,9 @@ copy $(OutDir)test.dll $(SolutionDir)..\..\..\code_app\build2\build\windows\huag
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>commonlog.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy $(OutDir)test.dll $(SolutionDir)..\..\..\release\win\x64\Release\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>

View File

@ -33,6 +33,9 @@ static struct Test_Map
{HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER ,HGPDTTOOLDB_TITLE_PLACE_CORRECTION_PAPER},
{HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD ,HGPDTTOOLDB_TITLE_AUTO_FLAT_FIELD},
{HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY ,HGPDTTOOLDB_TITLE_IMAGE_QUALITY},
{HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY ,HGPDTTOOLDB_TITLE_IMAGE_QUALITY},
{HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY_PHOTO ,HGPDTTOOLDB_TITLE_IMAGE_QUALITY_PHOTO },
{HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY_PHOTO ,HGPDTTOOLDB_TITLE_IMAGE_QUALITY_PHOTO },
{HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY ,HGPDTTOOLDB_TITLE_COLORCARD_IMAGEING_QUALITY},
{HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY ,HGPDTTOOLDB_TITLE_COLORCARD_BIAS_IMAGEING_QUALITY},
{HGPDTTOOLDB_NAME_CLARITY_QUALITY ,HGPDTTOOLDB_TITLE_CLARITY_QUALITY},
@ -62,7 +65,16 @@ static struct Test_Map
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_600DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_600DPI},
{HGPDTTOOLDB_NAME_GET_SN ,HGPDTTOOLDB_TITLE_GET_SN},
{HGPDTTOOLDB_NAME_KEY_INSPECTION ,HGPDTTOOLDB_TITLE_KEY_INSPECTION}
{HGPDTTOOLDB_NAME_KEY_INSPECTION ,HGPDTTOOLDB_TITLE_KEY_INSPECTION},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399 ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_3399},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_MORR_200DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_MORR_200DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_MORR_300DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_MORR_300DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI},
{HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI ,HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI}
};
static std::string StringToUtf(std::string strValue)
@ -413,8 +425,10 @@ static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int
break;
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY) == 0)
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY) == 0 ||
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY) == 0 ||
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY_PHOTO) == 0 ||
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY_PHOTO) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
@ -504,7 +518,17 @@ static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI) == 0)
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI) == 0
)
{
if (strcmp((char*)data, STATU_DESC_SCANNER_ERR_IMAGE_CORRECTION_FINISHED) != 0)
{
@ -517,12 +541,16 @@ static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int
}
wcscat(buf, wstr.c_str());
//ret = h->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);//结束恢复默认
bool correctFail = false;
int thre = 0;
if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION) == 0)
thre = 7;
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399) == 0)
thre = 15;
if (thre > 0)
{
if (g_currentCorrectType == 7)
if (g_currentCorrectType == thre)
{
while (1)
{
@ -561,6 +589,17 @@ static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int
{
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)buf, type);
}
//h->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);//结束恢复默认
unsigned int l = 0;
bool isOriImg = false;
int ret = h->io_control(IO_CTRL_CODE_ORIGINAL_IMAGE, (void*)&isOriImg, &l);
bool isMorr = false;
ret = h->io_control(IO_CTRL_CODE_SET_MORR, (void*)&isMorr, &l);
bool isLongText = false;
ret = h->io_control(IO_CTRL_CODE_SET_LONGTEXT, (void*)&isLongText, &l);
bool photoMode = false;
ret = h->io_control(IO_CTRL_CODE_SET_PICTURE_PHOTO_MODE, &photoMode, &l);
}
break;
case SANE_EVENT_ERROR:
@ -580,6 +619,9 @@ static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int
{
if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY_PHOTO) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY_PHOTO) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SCAN_WORKING_STATUS) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SKEW_DETECTION) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY) == 0
@ -603,7 +645,16 @@ static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI) == 0)
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI) == 0)
{
g_imageCount++;
@ -665,6 +716,9 @@ void test::init_test_map_()
test_map_[HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY] = &test::test_image_color_quality;
test_map_[HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY] = &test::test_image_gray_quality;
test_map_[HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY_PHOTO] = &test::test_image_color_quality_photo;
test_map_[HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY_PHOTO] = &test::test_image_gray_quality_photo;
test_map_[HGPDTTOOLDB_NAME_GET_DISTORTION_VAL] = &test::test_get_auto_distortion;
test_map_[HGPDTTOOLDB_NAME_SET_DISTORTION_VAL] = &test::test_set_auto_distortion;
test_map_[HGPDTTOOLDB_NAME_CONFIRM_DISTORTION_VAL] = &test::test_confirm_auto_distortion;
@ -692,13 +746,23 @@ void test::init_test_map_()
test_map_[HGPDTTOOLDB_NAME_BACKUP] = &test::test_backup;
test_map_[HGPDTTOOLDB_NAME_SHUTDOWN] = &test::test_shutdown;
test_map_[HGPDTTOOLDB_NAME_SET_FIRMWARE_LANGUAGE] = &test::test_set_firmware_language;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION] = &test::test_image_correct_all;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION] = &test::test_image_correct_all_306;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_200DPI] = &test::test_image_correct_rgb_200dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_200DPI] = &test::test_image_correct_gray_200dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI] = &test::test_image_correct_rgb_300dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI] = &test::test_image_correct_gray_300dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI] = &test::test_image_correct_rgb_600dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI] = &test::test_image_correct_gray_600dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI] = &test::test_image_correct_rgb_morr_200dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399] = &test::test_image_correct_all_3399;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI] = &test::test_image_correct_gray_morr_200dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI] = &test::test_image_correct_rgb_morr_300dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI] = &test::test_image_correct_gray_morr_300dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI] = &test::test_image_correct_rgb_longtext_200dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI] = &test::test_image_correct_gray_longtext_200dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI] = &test::test_image_correct_rgb_longtext_300dpi;
test_map_[HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI] = &test::test_image_correct_gray_longtext_300dpi;
}
int test::set_test(const wchar_t* name, const wchar_t* oper)
{
@ -785,6 +849,37 @@ void test::thread_dynamic_correct(std::string correctData)
}
}
void test::thread_dynamic_correct_3399(std::string correctData)
{
std::unique_lock<std::mutex> lock(m_lock);
while (g_currentCorrectType <= 14)
{
if (g_currentCorrectType > 1)
m_waitCorrect.wait(lock);
if (g_currentCorrectType == 0 || g_dynamicCorrectStatus == SCANNER_ERR_IMAGE_CORRECTION_FAIL)
{
break;
}
SANE_Bool type = true;
unsigned int len = sizeof(SANE_Bool);
int ret = helper_->io_control(IO_CTRL_CODE_GET_PAPER_ON, &type, &len);
if (!type)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"无纸", false);
return;
}
CorrectMode correctMode = m_correctModeMap_3399.at(g_currentCorrectType);
int dpi = correctMode.dpi;
bool isColor = correctMode.isColor;
bool isMorr = correctMode.isMorr;
bool isLongText = correctMode.isLongText;
ret = public_test_image_correct(correctData, dpi, isColor, isMorr, isLongText);
g_currentCorrectType++;
}
}
void test::thread_distortion()
{
std::unique_lock<std::mutex> lock(m_lock);
@ -1229,6 +1324,82 @@ int test::test_image_gray_quality(void* data)
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
int test::test_image_color_quality_photo(void* data)
{
if (!data)
{
return SCANNER_ERR_DATA_DAMAGED;
}
wchar_t* p = (wchar_t*)data;
std::string str;
int ret = SCANNER_ERR_OK,
dpi = 0;
unsigned int len = sizeof(int);
size_t strl = 0;
ret = wchar_to_char(str, p, &strl);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(strl);
ret = wchar_to_char(str, p, &strl);
if (str.empty())
{
return SCANNER_ERR_DATA_DAMAGED;
}
dpi = atoi(str.c_str());
}
if (dpi > 0)
{
ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, &dpi, &len);
bool photoMode = true;
ret = helper_->io_control(IO_CTRL_CODE_SET_PICTURE_PHOTO_MODE, &photoMode, &len);
}
if (ret != SCANNER_ERR_OK)
{
return -1;
}
const char* color = OPTION_VALUE_YSMS_24WCS;
unsigned int colorlen = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
int test::test_image_gray_quality_photo(void* data)
{
if (!data)
{
return SCANNER_ERR_DATA_DAMAGED;
}
wchar_t* p = (wchar_t*)data;
std::string str;
int ret = SCANNER_ERR_OK,
dpi = 0;
unsigned int len = sizeof(int);
size_t strl = 0;
ret = wchar_to_char(str, p, &strl);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(strl);
ret = wchar_to_char(str, p, &strl);
if (str.empty())
{
return SCANNER_ERR_DATA_DAMAGED;
}
dpi = atoi(str.c_str());
}
if (dpi > 0)
{
ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, &dpi, &len);
bool photoMode = true;
ret = helper_->io_control(IO_CTRL_CODE_SET_PICTURE_PHOTO_MODE, &photoMode, &len);
}
if (ret != SCANNER_ERR_OK)
{
return -1;
}
const char* color = OPTION_VALUE_YSMS_256JHD;
unsigned int colorlen = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
/* 获取自动计算畸变值 */
int test::test_get_auto_distortion(void* data)
{
@ -1874,7 +2045,7 @@ int test::public_test_image_correct(void* data, int dpi, bool isColor)
}
if (str.empty())
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"校正失败", false);
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"校正失败,校正数据为空", false);
return -1;
}
@ -1898,7 +2069,87 @@ int test::public_test_image_correct(void* data, int dpi, bool isColor)
return ret;
}
int test::test_image_correct_all(void* data)
int test::public_test_image_correct(std::string correctData, int dpi, bool isColor, bool isMorr, bool isLongText)
{
if (correctData.empty())
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"校正失败,校正数据为空", false);
return -1;
}
unsigned int l = correctData.size();
int ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &l);
const char* color = isColor ? OPTION_VALUE_YSMS_24WCS : OPTION_VALUE_YSMS_256JHD;
unsigned int colorlen = strlen(color);
ret = helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen);
SANE_Bool isOriImg = true;
ret = helper_->io_control(IO_CTRL_CODE_ORIGINAL_IMAGE, (void*)&isOriImg, &l);
if (isMorr)
ret = helper_->io_control(IO_CTRL_CODE_SET_MORR, (void*)&isMorr, &l);
if (isLongText)
ret = helper_->io_control(IO_CTRL_CODE_SET_LONGTEXT, (void*)&isLongText, &l);
ret = helper_->io_control(IO_CTRL_CODE_SET_CORRECT_IMAGE, &correctData[0], &l);
ret = helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
if (ret != SCANNER_ERR_OK)
return ret;
return ret;
}
int test::public_test_image_correct(void* data, int dpi, bool isColor, bool isMorr, bool isLongText)
{
if (!data)
{
return SCANNER_ERR_NO_DATA;
}
wchar_t* sc = (wchar_t*)data;
std::string str;
size_t len = 0;
int ret = wchar_to_char(str, sc, &len);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(len);
ret = wchar_to_char(str, sc, &len);
}
if (str.empty())
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"校正失败,校正数据为空", false);
return -1;
}
unsigned int l = str.size();
ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &l);
const char* color = isColor ? OPTION_VALUE_YSMS_24WCS : OPTION_VALUE_YSMS_256JHD;
unsigned int colorlen = strlen(color);
ret = helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen);
SANE_Bool isOriImg = true;
ret = ret = helper_->io_control(IO_CTRL_CODE_ORIGINAL_IMAGE, (void*)&isOriImg, &l);
if (isMorr)
ret = helper_->io_control(IO_CTRL_CODE_SET_MORR, (void*)&isMorr, &l);
if (isLongText)
ret = helper_->io_control(IO_CTRL_CODE_SET_LONGTEXT, (void*)&isLongText, &l);
ret = helper_->io_control(IO_CTRL_CODE_SET_CORRECT_IMAGE, &str[0], &l);
ret = helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
if (ret != SCANNER_ERR_OK)
return ret;
//helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"校正完成", true);
return ret;
}
int test::test_image_correct_all_306(void* data)
{
if (!data)
{
@ -1923,6 +2174,31 @@ int test::test_image_correct_all(void* data)
return SCANNER_ERR_OK;
}
int test::test_image_correct_all_3399(void* data)
{
if (!data)
{
return SCANNER_ERR_NO_DATA;
}
wchar_t* sc = (wchar_t*)data;
std::string str;
size_t len = 0;
int ret = wchar_to_char(str, sc, &len);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(len);
ret = wchar_to_char(str, sc, &len);
}
g_currentCorrectType = 1;
g_dynamicCorrectStatus = SCANNER_ERR_OK;
if (thread_dynamic_correct_handle.get() && thread_dynamic_correct_handle->joinable())
thread_dynamic_correct_handle->join();
thread_dynamic_correct_handle.reset(new std::thread(&test::thread_dynamic_correct_3399, this, str));
return SCANNER_ERR_OK;
}
int test::test_image_correct_rgb_200dpi(void* data)
{
return public_test_image_correct(data, 200, true);
@ -1949,6 +2225,46 @@ int test::test_image_correct_gray_600dpi(void* data)
return public_test_image_correct(data, 600, false);
}
int test::test_image_correct_rgb_morr_200dpi(void* data)
{
return public_test_image_correct(data, 200, true, true, false);
}
int test::test_image_correct_gray_morr_200dpi(void* data)
{
return public_test_image_correct(data, 200, false, true, false);
}
int test::test_image_correct_rgb_morr_300dpi(void* data)
{
return public_test_image_correct(data, 300, true, true, false);
}
int test::test_image_correct_gray_morr_300dpi(void* data)
{
return public_test_image_correct(data, 300, false, true, false);
}
int test::test_image_correct_rgb_longtext_200dpi(void* data)
{
return public_test_image_correct(data, 200, true, false, true);
}
int test::test_image_correct_gray_longtext_200dpi(void* data)
{
return public_test_image_correct(data, 200, false, false, true);
}
int test::test_image_correct_rgb_longtext_300dpi(void* data)
{
return public_test_image_correct(data, 300, true, false, true);
}
int test::test_image_correct_gray_longtext_300dpi(void* data)
{
return public_test_image_correct(data, 300, false, false, true);
}
DECL_API(int) func_test_init(void* init, ui_helper* helper)
{
if (test_ == nullptr)
@ -1996,7 +2312,16 @@ DECL_API(int) func_test_correct(bool isSuccess, int *currentIndex, bool *isCorre
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_300DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_300DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_600DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI) != 0)
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_600DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI) != 0 &&
wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI) != 0)
{
return 0;
}

View File

@ -58,6 +58,8 @@
#define HGPDTTOOLDB_TITLE_REBOOT_DEVICE L"重启设备"
/* 扫描图像质量确认 */
#define HGPDTTOOLDB_TITLE_IMAGE_QUALITY L"扫描图像质量确认"
/* 照片模式图像质量确认 */
#define HGPDTTOOLDB_TITLE_IMAGE_QUALITY_PHOTO L"照片模式图像质量确认"
/* 色卡纸成像质量评估 */
#define HGPDTTOOLDB_TITLE_COLORCARD_IMAGEING_QUALITY L"色卡纸成像质量评估"
/* 色卡纸偏色成像质量评估 */
@ -121,6 +123,25 @@
/* 获取设备序列号 */
#define HGPDTTOOLDB_TITLE_GET_SN L"获取设备序列号"
/*3399设备图像扫描校正*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_3399 L"设备图像扫描校正"
/*摩尔纹彩色图像扫描校正+200dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_MORR_200DPI L"摩尔纹彩色图像扫描校正+200dpi"
/*摩尔纹灰度图像扫描校正+200dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_MORR_200DPI L"摩尔纹灰度图像扫描校正+200dpi"
/*摩尔纹彩色图像扫描校正+300dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_MORR_300DPI L"摩尔纹彩色图像扫描校正+300dpi"
/*摩尔纹灰度图像扫描校正+300dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_MORR_300DPI L"摩尔纹灰度图像扫描校正+300dpi"
/*长文稿彩色图像扫描校正+200dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI L"长文稿彩色图像扫描校正+200dpi"
/*长文稿灰度图像扫描校正+200dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI L"长文稿灰度图像扫描校正+200dpi"
/*长文稿彩色图像扫描校正+300dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI L"长文稿彩色图像扫描校正+300dpi"
/*长文稿灰度图像扫描校正+300dpi*/
#define HGPDTTOOLDB_TITLE_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI L"长文稿灰度图像扫描校正+300dpi"
//////////////////////////////////////NAME//////////////////////////////////////
#define WRITE_CFG_NAME L"write-cfg"
@ -180,6 +201,10 @@
#define HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY L"IMAGE_COLOR_QUALITY"
/* 扫描图像灰度质量确认 */
#define HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY L"IMAGE_GRAY_QUALITY"
/* 照片模式图像彩色质量确认 */
#define HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY_PHOTO L"IMAGE_COLOR_QUALITY_PHOTO"
/* 照片模式图像灰度质量确认 */
#define HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY_PHOTO L"IMAGE_GRAY_QUALITY_PHOTO"
/* 色卡纸成像质量评估 */
#define HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY L"COLORCARD_IMAGEING_QUALITY"
/* 色卡纸偏色成像质量评估 */
@ -249,6 +274,25 @@
/*关键项检查*/
#define HGPDTTOOLDB_NAME_KEY_INSPECTION L"KEY_INSPECTION"
/*3399设备图像扫描校正*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_3399 L"IMAGE_CORRECTION_3399"
/*摩尔纹彩色图像扫描校正+200dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_200DPI L"IMAGE_CORRECTION_RGB_MORR_200DPI"
/*摩尔纹灰度图像扫描校正+200dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_200DPI L"IMAGE_CORRECTION_GRAY_MORR_200DPI"
/*摩尔纹彩色图像扫描校正+300dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_MORR_300DPI L"IMAGE_CORRECTION_RGB_MORR_300DPI"
/*摩尔纹灰度图像扫描校正+300dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_MORR_300DPI L"IMAGE_CORRECTION_GRAY_MORR_300DPI"
/*长文稿彩色图像扫描校正+200dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_200DPI L"IMAGE_CORRECTION_RGB_LONGTEXT_200DPI"
/*长文稿灰度图像扫描校正+200dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI L"IMAGE_CORRECTION_GRAY_LONGTEXT_200DPI"
/*长文稿彩色图像扫描校正+300dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_RGB_LONGTEXT_300DPI L"IMAGE_CORRECTION_RGB_LONGTEXT_300DPI"
/*长文稿灰度图像扫描校正+300dpi*/
#define HGPDTTOOLDB_NAME_IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI L"IMAGE_CORRECTION_GRAY_LONGTEXT_300DPI"
#define TEST_DLL
#ifdef TEST_DLL
@ -322,6 +366,7 @@ public:
private:
std::unique_ptr<std::thread> thread_dynamic_correct_handle;
void thread_dynamic_correct(std::string correctData);
void thread_dynamic_correct_3399(std::string correctData);
std::unique_ptr<std::thread> thread_distortion_handle;
void thread_distortion();
@ -330,6 +375,8 @@ private:
{
int dpi;
bool isColor;
bool isMorr;
bool isLongText;
};
@ -343,6 +390,24 @@ private:
{6, CorrectMode{600, false}}
};
std::map<int, CorrectMode> m_correctModeMap_3399
{
{1, CorrectMode{200, true, false, false}},
{2, CorrectMode{200, false, false, false}},
{3, CorrectMode{300, true, false, false}},
{4, CorrectMode{300, false, false, false}},
{5, CorrectMode{600, true, false, false}},
{6, CorrectMode{600, false, false, false}},
{7, CorrectMode{200, true, true, false}},
{8, CorrectMode{200, false, true, false}},
{9, CorrectMode{300, true, true, false}},
{10, CorrectMode{300, false, true, false}},
{11, CorrectMode{200, true, false, true}},
{12, CorrectMode{200, false, false, true}},
{13, CorrectMode{300, true, false, true}},
{14, CorrectMode{300, false, false, true}}
};
private:
std::string get_serial_num();
@ -398,6 +463,10 @@ private:
int test_image_color_quality(void* data);
/* 扫描图像灰度质量确认 */
int test_image_gray_quality(void* data);
/* 照片模式图像彩色质量确认 */
int test_image_color_quality_photo(void* data);
/* 照片模式图像灰度质量确认 */
int test_image_gray_quality_photo(void* data);
/* 获取自动计算畸变值 */
int test_get_auto_distortion(void* data);
int test_set_auto_distortion(void* data);
@ -440,12 +509,29 @@ private:
/*动态图像校正*/
int public_test_image_correct(std::string correctData, int dpi, bool isColor);
int public_test_image_correct(void* data, int dpi, bool isColor);
int test_image_correct_all(void* data);
int public_test_image_correct(std::string correctData, int dpi, bool isColor, bool isMorr, bool isLongText);
int public_test_image_correct(void* data, int dpi, bool isColor, bool isMorr, bool isLongText);
int test_image_correct_all_306(void* data);
int test_image_correct_all_3399(void* data);
/*普通模式动态校正*/
int test_image_correct_rgb_200dpi(void* data);
int test_image_correct_gray_200dpi(void* data);
int test_image_correct_rgb_300dpi(void* data);
int test_image_correct_gray_300dpi(void* data);
int test_image_correct_rgb_600dpi(void* data);
int test_image_correct_gray_600dpi(void* data);
/*摩尔纹加长文稿动态校正*/
int test_image_correct_rgb_morr_200dpi(void* data);
int test_image_correct_gray_morr_200dpi(void* data);
int test_image_correct_rgb_morr_300dpi(void* data);
int test_image_correct_gray_morr_300dpi(void* data);
int test_image_correct_rgb_longtext_200dpi(void* data);
int test_image_correct_gray_longtext_200dpi(void* data);
int test_image_correct_rgb_longtext_300dpi(void* data);
int test_image_correct_gray_longtext_300dpi(void* data);
};