优化帧数超时导致 走纸效率变低的问题

This commit is contained in:
modehua 2023-12-11 00:12:03 -08:00
parent 1efab70b36
commit 694eb2125d
11 changed files with 129 additions and 60 deletions

View File

@ -81,6 +81,16 @@ union CamZ_Reg_A_New
unsigned int dpi_200: 1; //dpi=1的时候 dpi_200=1 200dpi dpi=1的时候 dpi_200=0 300dpi dpi=0的时候 dpi_200=0 600dpi
};
};
union CamZ_Reg_11
{
int value;
struct
{
unsigned int div_reg:5;
unsigned int samp_reg:10;
unsigned int low_reg:10;
};
};
union SCAN_PWM

View File

@ -59,7 +59,7 @@ void CuoZhiMotor::reset()
mspCuozhiBackward.a,
mspCuozhiBackward.offset,
mspCuozhiBackward.finalDelay);
LOG("finalPeriod=%d Fmin=%d \n", mspCuozhiBackward.finalPeriod, mspCuozhiBackward.Fmin);
//printf("finalPeriod=%d Fmin=%d \n", mspCuozhiBackward.finalPeriod, mspCuozhiBackward.Fmin);
Motor::start(delays_forward, mspCuozhiBackward);
std::random_device rd; // obtain a random number from hardware
std::mt19937 gen(rd()); // seed the generator

View File

@ -155,6 +155,7 @@ HCamDevice::HCamDevice()
//devmem 0x40010040 32 0x00000B00 //灰度模式 VSNP值 0x10
//this->event_thread.reset(new std::thread(&HCamDevice::HtCamEventWorkThread, this));
//this->event_thread.reset(new std::thread(&HCamDevice::auto_duty_cycle,this));
for (int i = 0; i < 20; i++)
{
//HtCamReadADCReg(i, &val);
@ -323,6 +324,32 @@ void HCamDevice::HtCamSetPeriod(double reg_value)
printf("PWM占空比%d\r\n",rgb.NShort[1]);
HtCamWriteFpgaRegs(0x09,rgb.value);
}
// void HCamDevice::HtCamGetPeriod(double &reg_value)
// {
// int reg = HtCamReadFpgaRegs(0x11);
// }
// void HCamDevice::HtCamSetLowLevelTimer(double reg_value)
// {
// reg_value /= 100;
// CamZ_Reg_11 reg;
// reg.value = HtCamReadFpgaRegs(0x11);
// int crossover_period = reg.div_reg * 10;//单位是ns
// int cycle = 1 / 1.6119 * 100000000;//单位是s 转换为ns
// reg.low_reg = cycle * (1 - reg_value) / crossover_period;
// }
// void HCamDevice::auto_duty_cycle()
// {
// std::unique_lock<std::mutex> lock(auto_duty_wait);
// while (true)
// {
// wait_auto_duty_.wait(lock);
// }
// }
int HCamDevice::HtCamEventWorkThread(void)
{
struct pollfd pfd;

View File

@ -52,6 +52,7 @@ public:
void HtCamGetPeriod(uint8_t &reg_value);//获取扫描仪传感器占空比
void HtCamSetPeriod(double reg_value); //设置扫描仪传感器占空比
//void HtCamGetPeriod(double &reg_value); //获取扫描仪传感器占空比
void HtCamGetFrameCnt(uint32_t &val);//获取设置采集的帧数 需要采集的帧数设置为0x05表示采集六帧后停止
void HtCamSetFrameCnt(uint32_t val);//需要采集的帧数设置为0x05表示采集六帧后停止
@ -180,6 +181,10 @@ private:
std::shared_ptr<std::thread> event_thread = nullptr;
std::shared_ptr<std::thread> thread_auto_duty= nullptr;
//std::condition_variable auto_duty_wait;
//std::mutex auto_duty_lock_;
Camconfig* config = nullptr;
std::string _CAM_TYPE = "PYTHONZ_1200";

View File

@ -215,7 +215,7 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config)
uint32_t cnt = compute_frame(paper_size_ , val) ;
if (resolution_ == 2)
{
cnt -=1 ;
//cnt -=1 ;
}
video->HtCamSetFrameCnt(cnt);
@ -274,7 +274,7 @@ void MultiFrameCapture::waitsnapdone(int state)
m_glue.m_imageready(ip); //发一次空包
b_end_snap = true;
printf("!!!!!!!!!!!!!!!! m_cv_snapdone wait done :%f \n",sw.elapsed_ms());
printf("走纸结束,等待采集完成耗时:%f \n",sw.elapsed_ms());
}
bool MultiFrameCapture::IsImageQueueEmpty()
{
@ -331,23 +331,24 @@ void MultiFrameCapture::snaprun()
if (data)
{
if (i == 1)
if (i == 2)
{
uint32_t cnt = 25;
if (paper_size_ != (unsigned int)PaperSize::G400_MAXSIZE && !is_remove_morr_)
{
int val = resolution_ == 3 ? 600 :(resolution_ == 2?300:200);
cnt = compute_frame((unsigned int)PaperSize::G400_AUTO , val) ;
cnt *=sw.elapsed_ms();
cnt *=(sw.elapsed_ms() +3);
}
else
cnt = (info_ex.frame_index + 1) * sw.elapsed_ms();
cnt = (info_ex.frame_index + 3) * sw.elapsed_ms();
image_cb_(cnt);
img_wait_.notify_all();
// cv::imwrite("/home/root/test.bmp", mat);
//cv::imwrite("/home/root/test.bmp", mat);
//savebitmap(data,15552,512,"1.bmp");
printf("第二帧图像采集耗时:%f\r\n",sw.elapsed_ms());
}
HG_JpegCompressInfo info ;
@ -363,8 +364,8 @@ void MultiFrameCapture::snaprun()
//printf("获取数据 width:%d height:%d is_first:%d is_last:%d DataLength:%d\r\n",info_ex.width,info_ex.height,info.first_frame,info.last_frame,info.DataLength);
//printf("index_frame:%d\r\n",info.index_frame);
m_glue.m_imageready(info);
printf("采集图像耗时:%f\r\n",sw.elapsed_ms());
}
return ret;
};
@ -387,16 +388,16 @@ void MultiFrameCapture::snaprun()
int channels = color_mode_ == 1 ? 3 : 1;
int color_mode = video->HtCamGetColorMode();
int func_sig = 0;
int time_out = resolution_ == DPI_600 ? 2000 : 900; ///这个时间是根据每帧的数据量来进行调测的
int time_out = resolution_ == DPI_600 ? 2000 : 500; ///这个时间是根据每帧的数据量来进行调测的
if (is_remove_morr_)
{
time_out = 2000;
}
if (color_mode_)
{
time_out += 400;
}
// if (color_mode_)
// {
// time_out += 400;
// }
uint32_t frame_num = 0;
uint32_t frame_cnt = 0;
@ -404,7 +405,15 @@ void MultiFrameCapture::snaprun()
video->HtCamGetFrameCnt(frame_cnt);
printf("获取设置的帧数:%d\r\n",frame_cnt);
frame_info_.frame_index = frame_cnt + 1;
frame_info_.frame_index = frame_cnt; //这个值别乱改 获取出来8 是指 0 - 8 实际采集图像是9
// if(resolution_ == 1 && color_mode_ == 0)
{
//frame_info_.frame_index = frame_cnt; //这个地方很可能是FPGA 的bug 所以暂时先这么处理一下
//printf("特殊处理200dpi 灰度模式 采集流程\r\n");
}
// video->HtCamSetVsnpTime(ti);
// printf("设置 vsnp%d\r\n",ti);
//ti++;
@ -413,6 +422,8 @@ void MultiFrameCapture::snaprun()
// ti++;
StopWatch sw;
sw.reset();
for (size_t i = 1; i <= frame_info_.frame_index ; i++)
{
@ -426,11 +437,17 @@ void MultiFrameCapture::snaprun()
{
video->HtCamGetFrameNum(frame_num);
int ind = i; //已采集了的帧数
int val = frame_num - ind; //剩余还未采集的帧数
int val = frame_num - 1 - ind; //剩余还未采集的帧数
printf("val :%d frame_num:%d i:%d\r\n",val,frame_num,i);
while (val > 0)
int j = 0;
//if(resolution_ == 1 && color_mode_ == 0)
{
//j = 1; //这个地方很可能是FPGA 的bug 所以暂时先这么处理一下
//printf("特殊处理200dpi 灰度模式 采集流程 jjj r\n");
}
while (val > j)
{
//frame_info_.last_frame = val == 1 ? true : false;
frame_info_.frame_index = frame_num;
ind++;

View File

@ -286,7 +286,7 @@ void Scanner::runScan()
break;
}
printf("frame_time_:%d\r\n",frame_time_);
printf("一张纸所需要的采集时间:%dms\r\n",frame_time_);
if (sensor->waitPaperOut(frame_time_))
{
if (!m_isDoublePaper)
@ -297,6 +297,9 @@ void Scanner::runScan()
m_scaninfo.JamOutNum++;
printf("paper 卡纸了。。。。。\n");
}
else
error_code = (int)HG_ScannerStatus::DETECT_DOUBLE_FEED;
printf("error_code:%d\r\n",error_code);
capturer->waitsnapdone(error_code);//等待采集完成
isScaning = false;
break;
@ -306,13 +309,13 @@ void Scanner::runScan()
capturer->stopsnap(b_autosize);
error_code = m_isDoublePaper ? (int)HG_ScannerStatus::DETECT_DOUBLE_FEED : m_jamPaper ? (int)HG_ScannerStatus::PAPER_JAM :0;
capturer->waitsnapdone(error_code);//等待采集完成
{
m_DstScannum--;
m_scaninfo.RollerNum++;
m_scaninfo.TotalScanned++;
}
if (m_DstScannum == 0)
{
put(S_EVT_STOP_SCAN);
@ -321,7 +324,23 @@ void Scanner::runScan()
}
sw.reset();
while (meminfo->GetMemoryUsed() > 90.0f||(m_config.params.dpi ==0x03 && capturer->getimageremain()>1)) //内存占用高于75% 其实我觉得开发人员应该自己控制好这个内存大小,让他绝对不可能超过这个内存大小
////必须控制队列帧数。
while ( m_config.params.dpi == 0x01 && image_num_>=15)
{
printf("200DPI 图像队列过多,正在等待图像取走:%d\r\n",image_num_);
this_thread::sleep_for(std::chrono::milliseconds(300));
}
while ( m_config.params.dpi == 0x02 && image_num_ >= 8)
{
printf("300DPI 图像队列过多,正在等待图像取走:%d\r\n",image_num_);
this_thread::sleep_for(std::chrono::milliseconds(300));
}
while ( m_config.params.dpi == 0x03 && image_num_ >= 2)
{
printf("600DPI 图像队列过多,正在等待图像取走:%d\r\n",image_num_);
this_thread::sleep_for(std::chrono::milliseconds(300));
}
while (meminfo->GetMemoryUsed() > 90.0f) //内存占用高于75% 其实我觉得开发人员应该自己控制好这个内存大小,让他绝对不可能超过这个内存大小
{
if (sw.elapsed_s() < 50.0)
std::this_thread::yield();
@ -332,11 +351,6 @@ void Scanner::runScan()
break;
}
}
printf("一张纸完成时间:%f\r\n",sw1.elapsed_ms());
if( m_config.params.dpi == 3)
this_thread::sleep_for(std::chrono::milliseconds(3000));
}
isScaning = false;
m_DstScannum = 0;
@ -345,13 +359,10 @@ void Scanner::runScan()
capturer->setScanFlag(false);
capturer->stopsnap(b_autosize);
int t_delay = 500;//b_autosize ?350 : 200;
//int t_delay = m_config.params.dpi == 0x02 ? 150 : (m_config.params.dpi == 0x03 ? 350 : 100);
int t_delay = 500;
this_thread::sleep_for(std::chrono::milliseconds(t_delay)); //走纸多转一会儿 确保扫描传感器过了之后 纸能出完
LOG("\n--------------------------scan done --------------------------------\n");
}
void Scanner::CreatCorrectData(int correctmode)

View File

@ -61,7 +61,8 @@ public:
inline void ResetJamIn() { m_jamIn = false; }
inline bool IsScanning() { return isScaning; }
inline void close_v4l2() { capturer->close(); }
inline void list_image_num(int num) {image_num_ = num;}
int image_num_ = 0;
CaptureParams GetCaptureParams()
{
CaptureParams param;

View File

@ -261,9 +261,9 @@ HG_JpegCompressInfo UsbScanner::GetImage()
HG_JpegCompressInfo ret = {0};
if (m_images.Size() > 0 && !m_images.IsShutDown())
{
m_hgScanner->list_image_num(m_images.Size());
ret = m_images.Take();
imageremain--;
// LOG("aquired image index %d \n",++aquiredimgindex);
}
return ret;
}
@ -300,7 +300,6 @@ bool UsbScanner::GetImagequeueEmpty()
{
printf("队列剩余图像帧数:%d\r\n",m_images.Size());
}
return m_images.Size() == 0;
}

View File

@ -43,6 +43,7 @@ public:
virtual void close_v4l2()override;
std::string GetSysInfo();
int read_bulk(void *pdata, int length,int time = 1000);
int write_bulk(void *pdata, int length);

View File

@ -32,16 +32,16 @@ void ZouZhiMotor::speedRecover()
void ZouZhiMotor::speedConfig()
{
LOG("ZouZhiMotor speed=%d \n dpi=%d \n colormode=%d \n finalPeriod=%d \n Fmin=%d \n a=%.2f \n offset=%.2f \n stepnum=%.2f \n finalDelay=%.2f \n ",
m_zouparamex.speed,
m_zouparamex.dpi,
m_zouparamex.colormode,
m_zouparamex.mt_param.finalPeriod,
m_zouparamex.mt_param.Fmin,
m_zouparamex.mt_param.a,
m_zouparamex.mt_param.offset,
m_zouparamex.mt_param.stepnum,
m_zouparamex.mt_param.finalDelay);
// printf("ZouZhiMotor speed=%d \n dpi=%d \n colormode=%d \n finalPeriod=%d \n Fmin=%d \n a=%.2f \n offset=%.2f \n stepnum=%.2f \n finalDelay=%.2f \n ",
// m_zouparamex.speed,
// m_zouparamex.dpi,
// m_zouparamex.colormode,
// m_zouparamex.mt_param.finalPeriod,
// m_zouparamex.mt_param.Fmin,
// m_zouparamex.mt_param.a,
// m_zouparamex.mt_param.offset,
// m_zouparamex.mt_param.stepnum,
// m_zouparamex.mt_param.finalDelay);
delays.clear();

View File

@ -315,10 +315,8 @@ int main(int argc, char *argv[])
case USBCommand::GET_IMAGE:
{
HG_JpegCompressInfo info = m_scanner->GetImage();
//printf("USB error_code:%d\r\n",info.error_code);
if (info.pJpegData != nullptr && info.DataLength != 0 || info.error_code)
{
int tt = m_scanner->write_bulk((void *)&info, sizeof(int) * 8);
int index = 0;
int total = info.DataLength;