7010新增一个空包,空包作用是随错误码 一起传输
This commit is contained in:
parent
28962b775c
commit
bcd6a7ff39
|
@ -746,7 +746,7 @@ namespace setting3288dsp
|
||||||
|
|
||||||
struct HG_JpegCompressInfo
|
struct HG_JpegCompressInfo
|
||||||
{
|
{
|
||||||
unsigned int data_type;
|
unsigned int error_code;
|
||||||
unsigned int first_frame;
|
unsigned int first_frame;
|
||||||
unsigned int last_frame;
|
unsigned int last_frame;
|
||||||
unsigned int index_frame;
|
unsigned int index_frame;
|
||||||
|
|
|
@ -76,8 +76,11 @@ hg_scanner_306::hg_scanner_306(const char* dev_name,int pid, usb_io* io) :
|
||||||
,papersize(pid)
|
,papersize(pid)
|
||||||
,is_devs_sleep_(false)
|
,is_devs_sleep_(false)
|
||||||
,index_ (0)
|
,index_ (0)
|
||||||
, first_frame_total(0)
|
, first_frame_total_(0)
|
||||||
, last_frame_total(0)
|
, last_frame_total_(0)
|
||||||
|
, frame_length_(0)
|
||||||
|
, frame_width_(0)
|
||||||
|
, frame_hegiht_(0)
|
||||||
{
|
{
|
||||||
dsp_config.value = 0;
|
dsp_config.value = 0;
|
||||||
dsp_config.params_7010.enableLed = 1; //默认值
|
dsp_config.params_7010.enableLed = 1; //默认值
|
||||||
|
@ -242,11 +245,6 @@ void hg_scanner_306::thread_handle_usb_read(void)
|
||||||
}
|
}
|
||||||
if (ret == SCANNER_ERR_OK && usb.u32_Count > 0)
|
if (ret == SCANNER_ERR_OK && usb.u32_Count > 0)
|
||||||
{
|
{
|
||||||
if (!savestatus_.empty())
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = get_img_data_7010();
|
ret = get_img_data_7010();
|
||||||
sw.reset();
|
sw.reset();
|
||||||
if (ret != SCANNER_ERR_OK)
|
if (ret != SCANNER_ERR_OK)
|
||||||
|
@ -455,7 +453,6 @@ int hg_scanner_306::get_scanner_status(USBCB &usb)
|
||||||
return code ;
|
return code ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int k = 0;
|
|
||||||
int hg_scanner_306::get_img_data_7010()
|
int hg_scanner_306::get_img_data_7010()
|
||||||
{
|
{
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
|
@ -469,48 +466,53 @@ int hg_scanner_306::get_img_data_7010()
|
||||||
setting3288dsp::HG_JpegCompressInfo info;
|
setting3288dsp::HG_JpegCompressInfo info;
|
||||||
StopWatch sw;
|
StopWatch sw;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
int len = sizeof(int) * 8;
|
int len = sizeof(info);
|
||||||
ret = io_->read_bulk(&info, &len);
|
ret = io_->read_bulk(&info, &len);
|
||||||
|
|
||||||
int val = info.DataLength;
|
|
||||||
int width = info.width;
|
|
||||||
int hegiht = info.height;
|
|
||||||
|
|
||||||
|
|
||||||
//cv::Mat mat1 = cv::Mat(hegiht, width, CV_8UC1, jpgdata.data(), cv::Mat::AUTO_STEP);
|
|
||||||
//static int cnt = 0;
|
|
||||||
|
|
||||||
if (info.first_frame)
|
if (info.first_frame)
|
||||||
{
|
{
|
||||||
first_frame_total = info.index_frame;
|
frame_length_ = info.DataLength;
|
||||||
|
frame_width_ = info.width;
|
||||||
|
frame_hegiht_ = info.height;
|
||||||
|
first_frame_total_ = info.index_frame;
|
||||||
jpgdata_.clear();
|
jpgdata_.clear();
|
||||||
jpgdata_.resize(width * hegiht * first_frame_total);
|
jpgdata_.resize(frame_width_ * frame_hegiht_ * first_frame_total_);
|
||||||
|
|
||||||
index_ = 0;
|
index_ = 0;
|
||||||
}
|
}
|
||||||
|
if (info.last_frame)
|
||||||
|
{
|
||||||
|
std::vector<unsigned char> data_;
|
||||||
|
data_.resize(frame_length_);
|
||||||
|
ret = io_->read_bulk(&data_[0], &frame_length_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = io_->read_bulk(&jpgdata_[index_], &frame_length_);
|
||||||
|
index_ += frame_length_;
|
||||||
|
last_frame_total_ = info.index_frame;
|
||||||
|
}
|
||||||
|
|
||||||
ret = io_->read_bulk(&jpgdata_[index_], &val);
|
|
||||||
index_ += val;
|
|
||||||
|
|
||||||
if (info.last_frame)
|
if (info.last_frame)
|
||||||
{
|
{
|
||||||
|
if (info.error_code)
|
||||||
|
{
|
||||||
|
std::vector<unsigned char>().swap(jpgdata_); //回收空间 clear只能清空元素
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
//return 0;
|
//return 0;
|
||||||
last_frame_total = info.index_frame;
|
|
||||||
|
|
||||||
int frame_ind = first_frame_total - last_frame_total;
|
|
||||||
|
|
||||||
mat_width = width;
|
int frame_ind = first_frame_total_ - last_frame_total_;
|
||||||
mat_height = (hegiht * first_frame_total) - (hegiht * frame_ind);
|
|
||||||
|
mat_width = frame_width_;
|
||||||
|
mat_height = (frame_hegiht_ * first_frame_total_) - (frame_hegiht_ * frame_ind);
|
||||||
std::shared_ptr<tiny_buffer> image_data_(aquire_memory(mat_width * mat_height));
|
std::shared_ptr<tiny_buffer> image_data_(aquire_memory(mat_width * mat_height));
|
||||||
|
|
||||||
unsigned int size1 = mat_height;
|
unsigned int size1 = mat_height;
|
||||||
void* l = image_data_->data(0, &size1);
|
void* l = image_data_->data(0, &size1);
|
||||||
memcpy(l, jpgdata_.data(), mat_width * mat_height);
|
memcpy(l, jpgdata_.data(), mat_width * mat_height);
|
||||||
|
|
||||||
//cv::Mat mat = cv::Mat(hegiht * first_frame_total, width, CV_8UC1, jpgdata_.data(), cv::Mat::AUTO_STEP);
|
|
||||||
//cv::imwrite("C://image//get_img_data_7010" + to_string(k) + ".jpg", mat);
|
|
||||||
k++;
|
|
||||||
ret = save_usb_data(image_data_);
|
ret = save_usb_data(image_data_);
|
||||||
index_ = 0;
|
index_ = 0;
|
||||||
|
|
||||||
|
@ -886,47 +888,36 @@ int hg_scanner_306::get_correction_image(int inx , int dpi, int mode)
|
||||||
int len = image_info.info.params.datalen;
|
int len = image_info.info.params.datalen;
|
||||||
imagedata.resize(len);
|
imagedata.resize(len);
|
||||||
|
|
||||||
|
|
||||||
if (ret == SCANNER_ERR_OK)
|
if (ret == SCANNER_ERR_OK)
|
||||||
ret = io_->read_bulk(&imagedata[0], &len);
|
ret = io_->read_bulk(&imagedata[0], &len);
|
||||||
if (imagedata.empty())
|
if (imagedata.empty())
|
||||||
{
|
{
|
||||||
return SCANNER_ERR_NO_DATA;
|
return SCANNER_ERR_NO_DATA;
|
||||||
}
|
}
|
||||||
cv::ImreadModes rmc = cv::IMREAD_GRAYSCALE;;// image_info.info.params.colormode ? cv::IMREAD_COLOR : cv::IMREAD_GRAYSCALE;
|
cv::ImreadModes rmc = cv::IMREAD_GRAYSCALE;
|
||||||
cv::Mat mat = cv::imdecode(imagedata, rmc);//color BGR
|
cv::Mat mat = cv::imdecode(imagedata, rmc);//color BGR
|
||||||
|
|
||||||
//if (mat.channels() == 3)
|
|
||||||
//cv::cvtColor(mat, mat, CV_BGR2RGB);
|
|
||||||
|
|
||||||
if (mat.empty())
|
if (mat.empty())
|
||||||
{
|
{
|
||||||
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_correction_image image is NULL:%d\n", image_info.info.params.status);
|
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_correction_image image is NULL:%d\n", image_info.info.params.status);
|
||||||
return SCANNER_ERR_NO_DATA; //只要有一张图没有 直接退了
|
return SCANNER_ERR_NO_DATA; //只要有一张图没有 直接退了
|
||||||
}
|
}
|
||||||
|
|
||||||
float f = 0.0;
|
float f = 0.0;
|
||||||
|
|
||||||
get_devs_distortion_check_val(f, dpi, i);
|
get_devs_distortion_check_val(f, dpi, i);
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
{
|
{
|
||||||
image_info.vratio = f;
|
image_info.vratio = f;
|
||||||
white_mat = mat;
|
white_mat = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
image_info.hratio = f;
|
image_info.hratio = f;
|
||||||
black_mat = mat;
|
black_mat = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//cv::imwrite("C://image//correction_image_white_mat" + to_string(inx) + ".bmp", white_mat);
|
|
||||||
//cv::imwrite("C://image//correction_image_black_mat" + to_string(inx) + ".bmp", black_mat);
|
|
||||||
|
|
||||||
ret = hg_imgproc::correction_image(ImagePrc_pHandle_, image_info.flat_lut, black_mat, white_mat);
|
ret = hg_imgproc::correction_image(ImagePrc_pHandle_, image_info.flat_lut, black_mat, white_mat);
|
||||||
|
|
||||||
correction_image_map_[inx] = image_info;
|
correction_image_map_[inx] = image_info;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -63,7 +63,23 @@ private:
|
||||||
int readusb(USBCB &usb);
|
int readusb(USBCB &usb);
|
||||||
int pop_image(void);
|
int pop_image(void);
|
||||||
int get_scanner_status(USBCB &usb);
|
int get_scanner_status(USBCB &usb);
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* 注意事项1:7010按帧传输数据 */
|
||||||
|
/* 注意事项2:7010最后一帧为空包,需把最后一帧数据剔除 */
|
||||||
|
/* 注意事项3:7010最后一帧主要作用是反馈当前纸张问题状态码 error_code */
|
||||||
|
/************************************************************************/
|
||||||
int get_img_data_7010();
|
int get_img_data_7010();
|
||||||
|
/*********************获取校正数据***************/
|
||||||
|
/* inx:序号 */
|
||||||
|
/* dpi:1--->200dpi 2--->300dpi 3--->600dpi */
|
||||||
|
/* mode:0 灰度 1彩色 */
|
||||||
|
/************************************************/
|
||||||
|
int get_correction_image(int inx, int dpi, int mode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int writedown_device_configuration(bool type =false,setting_hardware::HGSCANCONF_7010 *d = NULL);
|
int writedown_device_configuration(bool type =false,setting_hardware::HGSCANCONF_7010 *d = NULL);
|
||||||
void writedown_image_configuration(void);
|
void writedown_image_configuration(void);
|
||||||
void printf_devconfig(setting_hardware::HGSCANCONF_7010 *d = NULL);
|
void printf_devconfig(setting_hardware::HGSCANCONF_7010 *d = NULL);
|
||||||
|
@ -71,11 +87,8 @@ private:
|
||||||
int get_devs_distortion_check_val(float& data, int dpi, int dir);//获取设备畸变值 DPI=1、2、3; dir = 0,1;
|
int get_devs_distortion_check_val(float& data, int dpi, int dir);//获取设备畸变值 DPI=1、2、3; dir = 0,1;
|
||||||
|
|
||||||
setting3288dsp::HG_JpegCompressInfo frame_info_;
|
setting3288dsp::HG_JpegCompressInfo frame_info_;
|
||||||
///////////////////////7010专有协议,获取校正数据//////////////////////
|
|
||||||
//inx:序号//
|
|
||||||
//dpi:1--->200 2--->300 3--->600//
|
|
||||||
//mode:0 灰度 1彩色
|
|
||||||
int get_correction_image(int inx ,int dpi,int mode);
|
|
||||||
private:
|
private:
|
||||||
std::vector<int> savestatus_;
|
std::vector<int> savestatus_;
|
||||||
setting_hardware::HGSCANCONF_7010 dsp_config;
|
setting_hardware::HGSCANCONF_7010 dsp_config;
|
||||||
|
@ -83,9 +96,11 @@ private:
|
||||||
bool is_devs_sleep_;
|
bool is_devs_sleep_;
|
||||||
|
|
||||||
|
|
||||||
int first_frame_total; //设置的帧数
|
int first_frame_total_; //设置的帧数
|
||||||
int last_frame_total; //实际采集的帧数
|
int last_frame_total_; //实际采集的帧数
|
||||||
|
int frame_length_ ;
|
||||||
|
int frame_width_ ;
|
||||||
|
int frame_hegiht_ ;
|
||||||
|
|
||||||
std::vector<unsigned char> jpgdata_;
|
std::vector<unsigned char> jpgdata_;
|
||||||
int index_;
|
int index_;
|
||||||
|
|
|
@ -1767,7 +1767,7 @@ namespace hg_imgproc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define GAMMA_EX 2.0f
|
#define GAMMA_EX 1.7f
|
||||||
#define BLACK_OFFSET 8
|
#define BLACK_OFFSET 8
|
||||||
|
|
||||||
void fittingLUT(const std::vector<unsigned char>& points, unsigned char min_value, unsigned char max_value, unsigned char* data)
|
void fittingLUT(const std::vector<unsigned char>& points, unsigned char min_value, unsigned char max_value, unsigned char* data)
|
||||||
|
|
Loading…
Reference in New Issue