调整整体出图流程及校正

This commit is contained in:
modehua 2023-09-03 20:28:08 -07:00
parent 5a8f86b81b
commit 96e71d9415
8 changed files with 54 additions and 65 deletions

View File

@ -4,8 +4,7 @@
CuoZhiMotor::CuoZhiMotor() CuoZhiMotor::CuoZhiMotor()
: Motor(motorPorts_Cuozhi) : Motor(motorPorts_Cuozhi)
{ {
//auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV; auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV;
auto t_smbtype = MotorConfig::MTBDType::MT_TMC;
m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, 4, 1, 1); m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, 4, 1, 1);
speedConfig(); speedConfig();
mspCuozhiFeeding = {.finalPeriod = 1427500, .Fmin = 2027500, .stepnum = 30, .a = 100, .offset = 4, .finalDelay = 3000}; mspCuozhiFeeding = {.finalPeriod = 1427500, .Fmin = 2027500, .stepnum = 30, .a = 100, .offset = 4, .finalDelay = 3000};
@ -101,8 +100,7 @@ void CuoZhiMotor::feeding()
void CuoZhiMotor::speedChange(int speed, int dpi, int colormode) // speed should be in range [0,5] (by ply,at 2019.5.23) void CuoZhiMotor::speedChange(int speed, int dpi, int colormode) // speed should be in range [0,5] (by ply,at 2019.5.23)
{ {
//auto t_smbtype = smbtype == SMBType::MB_DRV_8825 ? MotorConfig::MTBDType::MT_DRV : MotorConfig::MTBDType::MT_TMC; auto t_smbtype = smbtype == SMBType::MB_DRV_8825 ? MotorConfig::MTBDType::MT_DRV : MotorConfig::MTBDType::MT_TMC;
auto t_smbtype = MotorConfig::MTBDType::MT_TMC;
m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, speed, colormode, dpi); m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, speed, colormode, dpi);
speedConfig(); speedConfig();
} }

View File

@ -101,7 +101,7 @@ HCamDevice::HCamDevice()
v4lWidth = 5184;//@300dpi 5184 @600dpi 5184*2 v4lWidth = 5184;//@300dpi 5184 @600dpi 5184*2
v4lHeight = 513 ;//* 3;//color_h/gray_h = 3 比如目标复原图像高度为128 则灰度需要FPGA采集128 彩色采集128*3 v4lHeight = 513 ;//* 3;//color_h/gray_h = 3 比如目标复原图像高度为128 则灰度需要FPGA采集128 彩色采集128*3
v4lBufferCount = 10; v4lBufferCount = 30;
v4l2buftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; v4l2buftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
nplanes = 1; // only use one plane nplanes = 1; // only use one plane
drivertype = V4L2_CAP_VIDEO_CAPTURE_MPLANE; drivertype = V4L2_CAP_VIDEO_CAPTURE_MPLANE;
@ -845,12 +845,12 @@ void HCamDevice::HtCamChangeExposureValueB(uint32_t* value)
return ; return ;
} }
uint32_t *pCamCtrlReg = virBaseAddr; uint32_t *pCamCtrlReg = virBaseAddr;
pCamCtrlReg[5] = value[1]<<16;//G 通道 pCamCtrlReg[5] = value[0]<<16;//G 通道
std::this_thread::sleep_for(std::chrono::milliseconds(5)); std::this_thread::sleep_for(std::chrono::milliseconds(5));
CamZ_Reg_2Short rgb; CamZ_Reg_2Short rgb;
rgb.value = HtCamReadFpgaRegs(0x06); rgb.value = HtCamReadFpgaRegs(0x06);
rgb.NShort[0] = value[0]; // R通道 rgb.NShort[0] = value[1]; // R通道
rgb.NShort[1] = value[2]; //B 通道 rgb.NShort[1] = value[2]; //B 通道
HtCamWriteFpgaRegs(0x06,rgb.value); HtCamWriteFpgaRegs(0x06,rgb.value);
@ -879,11 +879,11 @@ void HCamDevice::HtCamChangeExposureValueF(uint32_t* value)
return ; return ;
} }
uint32_t *pCamCtrlReg = virBaseAddr; uint32_t *pCamCtrlReg = virBaseAddr;
pCamCtrlReg[11] = value[1] << 16;//G 通道 pCamCtrlReg[11] = value[0] << 16;//G 通道
std::this_thread::sleep_for(std::chrono::milliseconds(5)); std::this_thread::sleep_for(std::chrono::milliseconds(5));
CamZ_Reg_2Short rgb; CamZ_Reg_2Short rgb;
rgb.value = HtCamReadFpgaRegs(0x0C); rgb.value = HtCamReadFpgaRegs(0x0C);
rgb.NShort[0] = value[0];// R通道 rgb.NShort[0] = value[1];// R通道
rgb.NShort[1] = value[2]; //B 通道 rgb.NShort[1] = value[2]; //B 通道
HtCamWriteFpgaRegs(0x0C,rgb.value); HtCamWriteFpgaRegs(0x0C,rgb.value);

View File

@ -64,7 +64,7 @@ public:
void HtCamSetStSp(int start_sample);//0x0d //2023 /8/23 灰度彩色默认200 //更具不同的颜色模式设置不同的st_sp //影响到图像的偏移 void HtCamSetStSp(int start_sample);//0x0d //2023 /8/23 灰度彩色默认200 //更具不同的颜色模式设置不同的st_sp //影响到图像的偏移
void HtCamGetStSp(uint32_t &start_sample); void HtCamGetStSp(uint32_t &start_sample);
void HtCamSetVsnpTime(int color); void HtCamSetVsnpTime(int color); //相位
void HtCamChangeExposureValueF(uint32_t* value); //曝光值设置 void HtCamChangeExposureValueF(uint32_t* value); //曝光值设置
void HtCamChangeExposureValueB(uint32_t* value); //曝光值设置 void HtCamChangeExposureValueB(uint32_t* value); //曝光值设置

View File

@ -189,7 +189,7 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config)
FPGAConfigParam fpgaparam = GetFpgaparam(config_dpi, config_color); FPGAConfigParam fpgaparam = GetFpgaparam(config_dpi, config_color);
video->HtCamSetSpTime(fpgaparam.Sp,fpgaparam.Sp - 49); // 2344 灰色 //2023-8-10 最新2650 video->HtCamSetSpTime(fpgaparam.Sp, 49); // 2344 灰色 //2023-8-10 最新2650
if (color_mode_) if (color_mode_)
{ {
video->HtCamSetSpTime2(fpgaparam.HRatio); video->HtCamSetSpTime2(fpgaparam.HRatio);
@ -342,22 +342,6 @@ void MultiFrameCapture::configFPGAParam(int mode, int dpi)
video->HtCamChangeExposureValueF(fpgaparam.ExposureF); video->HtCamChangeExposureValueF(fpgaparam.ExposureF);
video->HtCamChangeExposureValueB(fpgaparam.ExposureB); video->HtCamChangeExposureValueB(fpgaparam.ExposureB);
std::vector<unsigned int> vals={fpgaparam.ExposureF[0],fpgaparam.ExposureF[1],fpgaparam.ExposureF[2],fpgaparam.ExposureB[0],fpgaparam.ExposureB[1],fpgaparam.ExposureB[2]};
unsigned int max_val=0;
for (size_t i = 0; i < vals.size(); i++)
{
if(i==0)
max_val = vals[i];
else
{
if(max_val <= vals[i])
max_val = vals[i];
}
}
printf("---------- max_val = %d \n",max_val+15);
video->HtCamSetSpTime(fpgaparam.Sp,max_val+15);
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
@ -392,11 +376,11 @@ int MultiFrameCapture::color()
#include "bmp.h" #include "bmp.h"
static int cnt = 0;
void MultiFrameCapture::snaprun() void MultiFrameCapture::snaprun()
{ {
//frame_info 发送得数据信息 channels 图像位深 num 需要取得帧数 time_out读图超时时间设置 //frame_info 发送得数据信息 channels 图像位深 num 需要取得帧数 time_out读图超时时间设置
auto snap_func = [this](V4L2_DATAINFO_Ex frame_info, int channels,int time_out) auto snap_func = [this](V4L2_DATAINFO_Ex frame_info, int channels,int time_out,int i)
{ {
StopWatch sw; StopWatch sw;
sw.reset(); sw.reset();
@ -408,21 +392,20 @@ void MultiFrameCapture::snaprun()
printf("----------------获取图像超时或者失败------------\r\n"); printf("----------------获取图像超时或者失败------------\r\n");
return ret; return ret;
} }
uint32_t sendLine = video->HtCamReadFpgaRegs(0x000e);////0x000e 取出来的实际行数 uint32_t sendLine = video->HtCamReadFpgaRegs(0x000e);////0x000e 取出来的实际行数
//printf("--------------fpga send line ------------:%d\r\n",sendLine); //printf("--------------fpga send line ------------:%d\r\n",sendLine);
if (data) if (data)
{ {
cv::Mat mat = cv::Mat(frame_info.height, frame_info.width, CV_8UC1, data, cv::Mat::AUTO_STEP); //cv::Mat mat = cv::Mat(frame_info.height, frame_info.width, CV_8UC1, data, cv::Mat::AUTO_STEP);
//cv::imwrite("/home/root/test.png", mat); //cv::imwrite("/home/root/test.png", mat);
// printf("--------------frame_index------------:%d\r\n",frame_index); // printf("--------------frame_index------------:%d\r\n",frame_index);
if (cnt == 2) if (i == 5)
{ {
//cv::imwrite("/home/root/test.bmp", mat); //cv::imwrite("/home/root/test.bmp", mat);
//cv::imwrite("/home/root/test.bmp", mat); //cv::imwrite("/home/root/test.bmp", mat);
//savebitmap(data,15552,512,"1.bmp"); //savebitmap(data,15552,512,"1.bmp");
} }
cnt++;
//frame_info.mat = mat.clone(); //frame_info.mat = mat.clone();
//JpegCompress cmp(90); //JpegCompress cmp(90);
@ -440,18 +423,18 @@ void MultiFrameCapture::snaprun()
info.width = frame_info.width; info.width = frame_info.width;
info.height = frame_info.height; info.height = frame_info.height;
// printf("获取数据 width:%d height:%d is_first:%d is_last:%d DataLength:%d\r\n",frame_info.width,frame_info.height,info.first_frame,info.last_frame,info.DataLength); printf("获取数据 width:%d height:%d is_first:%d is_last:%d DataLength:%d\r\n",frame_info.width,frame_info.height,info.first_frame,info.last_frame,info.DataLength);
//cv::imwrite("/home/root/opencv"+to_string(cnt_++)+".bmp",frame.mat); //cv::imwrite("/home/root/opencv"+to_string(cnt_++)+".bmp",frame.mat);
m_glue.m_imageready(info); m_glue.m_imageready(info);
//m_frameinfos.Put(frame_info); //m_frameinfos.Put(frame_info);
//printf("采集图像耗时:%f\r\n",sw.elapsed_ms()); printf("采集图像耗时:%f\r\n",sw.elapsed_ms());
} }
return ret; return ret;
}; };
static int ti = 0; //static int ti = 0;
while (b_snap_run) while (b_snap_run)
{ {
std::unique_lock<std::mutex> lock(m_mtx_snap); std::unique_lock<std::mutex> lock(m_mtx_snap);
@ -478,7 +461,7 @@ void MultiFrameCapture::snaprun()
video->HtCamGetFrameCnt(frame_cnt); video->HtCamGetFrameCnt(frame_cnt);
frame_info.frame_index = frame_cnt; frame_info.frame_index = frame_cnt;
//video->HtCamSetVsnpTime(ti); //video->HtCamSetVsnpTime(6);
//printf("设置 vsnp%d\r\n",ti); //printf("设置 vsnp%d\r\n",ti);
//ti++; //ti++;
@ -491,12 +474,12 @@ void MultiFrameCapture::snaprun()
for (size_t i = 1; i <= frame_cnt; i++) for (size_t i = 1; i <= frame_cnt; i++)
{ {
//printf("***********设置的帧数:%d 正在采集第[%d]帧************\r\n",frame_cnt,i); printf("***********设置的帧数:%d 正在采集第[%d]帧************\r\n",frame_cnt,i);
frame_info.first_frame = i == 1 ? true : false; frame_info.first_frame = i == 1 ? true : false;
frame_info.last_frame = i == frame_cnt ? true : false; frame_info.last_frame = i == frame_cnt ? true : false;
func_sig = snap_func(frame_info, channels,time_out); func_sig = snap_func(frame_info, channels,time_out,i);
if (func_sig == -1 ) //当前帧取图超时,在取一次!!! 一直超时 不就卡死了??? 这个地方还是需要加个时间限制几秒内一帧未取出就退了,返回异常状态吧? if (func_sig == -1 ) //当前帧取图超时,在取一次!!! 一直超时 不就卡死了??? 这个地方还是需要加个时间限制几秒内一帧未取出就退了,返回异常状态吧?
{ {
i--; i--;
@ -513,12 +496,12 @@ void MultiFrameCapture::snaprun()
{ {
video->HtCamGetFrameNum(frame_num); video->HtCamGetFrameNum(frame_num);
int val = frame_num - i; //剩余还未采集的帧数 int val = frame_num - i; //剩余还未采集的帧数
int ind = i++; //只是计数确认采集到低多少帧,无其他实用意义 int ind = i + 1; //只是计数确认采集到低多少帧,无其他实用意义
while (val) while (val)
{ {
frame_info.last_frame = val == 1 ? true : false; frame_info.last_frame = val == 1 ? true : false;
func_sig = snap_func(frame_info, channels,time_out);//同上面一样 func_sig = snap_func(frame_info, channels,time_out ,ind);//同上面一样
//printf("-----------当前采集到第:[%d]帧 CIS总共采集[%d]帧 -------\r\n",ind,frame_num); printf("-----------当前采集到第:[%d]帧 CIS总共采集[%d]帧 -------\r\n",ind,frame_num);
if (func_sig == -1 ) if (func_sig == -1 )
{ {
@ -542,7 +525,9 @@ void MultiFrameCapture::snaprun()
////////////////////////////采集过快会导致队列堆积///////////////////////// ////////////////////////////采集过快会导致队列堆积/////////////////////////
////////////////////////////所以这个延时是采集速度和传图速度的差值///////////////////////// ////////////////////////////所以这个延时是采集速度和传图速度的差值/////////////////////////
////////////////////////////DPI 颜色不同 会导致数据大小不同所以这个地方延时肯定不一样 目前 60是200dpi///////////////////////// ////////////////////////////DPI 颜色不同 会导致数据大小不同所以这个地方延时肯定不一样 目前 60是200dpi/////////////////////////
this_thread::sleep_for(std::chrono::milliseconds(35)); int mill = resolution_ == DPI_600 ? 60 * 10 : 10;
this_thread::sleep_for(std::chrono::milliseconds(mill));
} }
video->HtCamStopVideoCapturing(); video->HtCamStopVideoCapturing();
@ -613,8 +598,10 @@ void MultiFrameCapture::procimage()
static int temp_val = 0; static int temp_val = 0;
bool MultiFrameCapture::saveLutImg(int dpi, int mode, bool black) bool MultiFrameCapture::saveLutImg(int dpi, int mode, bool black)
{ {
printf("校正DPI[%d] 校正颜色:%s\n",dpi==1?200:(dpi==2?300:600),mode == IMAGE_COLOR?"彩色":"灰色");
int config_dpi = dpi == 1 ? 2 : dpi; int config_dpi = dpi == 1 ? 2 : dpi;
const int offset_indexs[] = {3, 4, 5, 2, 1, 0 ,0, 1, 2, 5, 4, 3}; const int offset_indexs[] = {3, 4, 5, 2, 1, 0 ,0, 1, 2, 5, 4, 3};
int channels = mode == IMAGE_COLOR ? 3 : 1; int channels = mode == IMAGE_COLOR ? 3 : 1;
int height = 60; int height = 60;
int width = config_dpi == 0x02 ? 864 : (config_dpi == 0x03 ? 1728 : 864); int width = config_dpi == 0x02 ? 864 : (config_dpi == 0x03 ? 1728 : 864);
@ -943,9 +930,9 @@ void MultiFrameCapture::correctcolor(int correctmode)
{ {
StopWatch sw_correct; StopWatch sw_correct;
std::string loginfo = "Start Correctcolor 300DPI Gray \r\n"; std::string loginfo = "Start Correctcolor 300DPI Gray \r\n";
printf("----------- %s \n",loginfo.c_str()); //printf("----------- %s \n",loginfo.c_str());
//creatcorrectconfig(0x02, IMAGE_GRAY); //creatcorrectconfig(0x02, IMAGE_GRAY);
printf("----------- done \n",loginfo.c_str()); //printf("----------- done \n",loginfo.c_str());
loginfo = "Start Correctcolor 300DPI COLOR \r\n"; loginfo = "Start Correctcolor 300DPI COLOR \r\n";
printf("----------- %s \n",loginfo.c_str()); printf("----------- %s \n",loginfo.c_str());
@ -1067,8 +1054,9 @@ void MultiFrameCapture::openDevice(int dpi, int mode)
configFPGAParam(config_color, config_dpi); configFPGAParam(config_color, config_dpi);
printf(" -----------------------resolution = %d config_color = %d config_dpi:%d------------------\r\n",resolution_, config_color,config_dpi); printf(" -----------------------resolution = %d config_color = %d config_dpi:%d------------------\r\n",resolution_, config_color,config_dpi);
{ {
video->HtCamSetFrameCnt(1); int val = 1;
printf(" -----------------------设置帧数:%d------------------\r\n",cnt); video->HtCamSetFrameCnt(val);
printf(" -----------------------设置帧数:%d------------------\r\n",val);
} }

View File

@ -12,7 +12,7 @@ class Gpio;
class GpioOut; class GpioOut;
#define WIDTH 5184 #define WIDTH 5184
#define HEIGHT 513 //只能为3的倍数 #define HEIGHT 650 //只能为3的倍数
#define DPI_600 0 #define DPI_600 0
#define DPI_300 1 #define DPI_300 1
#define COLOR 1 #define COLOR 1

View File

@ -210,14 +210,10 @@ void Scanner::runScan()
{ {
LOG("-------------Scanner RunScan Start-------------\r\n"); LOG("-------------Scanner RunScan Start-------------\r\n");
capturer->open(); capturer->open();
printf("11111111111111111111\r\n");
motorZouzhi.start(); motorZouzhi.start();
motorCuozhi.pauseWaitForThread(); motorCuozhi.pauseWaitForThread();
//capturer->open();
//sensor->enableDoubleSensor(false);
if (!isPaperInit) if (!isPaperInit)
{ {
@ -225,10 +221,7 @@ void Scanner::runScan()
isPaperInit = true; isPaperInit = true;
} }
// for (size_t i = 0; i < 16; i++)
// {
// std::cout << string_format("reg[%d] = 0x%08x", i, capturer->read(i)) << std::endl;
// }
this_thread::sleep_for(std::chrono::milliseconds(200)); this_thread::sleep_for(std::chrono::milliseconds(200));
imageindex = 0; imageindex = 0;
//*capturer->setFPGATriggerMode(false, 0); //*capturer->setFPGATriggerMode(false, 0);
@ -238,11 +231,8 @@ void Scanner::runScan()
sensor->resetPaperPin(); sensor->resetPaperPin();
capturer->clearimages(); capturer->clearimages();
capturer->resetimageremain(); capturer->resetimageremain();
capturer->setScanFlag(true); capturer->setScanFlag(true);
bool b_autosize = m_config.params.pageSize==(int)PaperSize::G400_AUTO || bool b_autosize = m_config.params.pageSize==(int)PaperSize::G400_AUTO ||
m_config.params.pageSize==(int)PaperSize::G400_MAXAUTO || m_config.params.pageSize==(int)PaperSize::G400_MAXAUTO ||
@ -269,7 +259,7 @@ void Scanner::runScan()
} }
sensor->enableDoubleSensor(m_config.params.doubleFeeded); sensor->enableDoubleSensor(m_config.params.doubleFeeded);
LOG("enableDoubleSensor QQQQQQQ:%s %s\n", m_config.params.doubleFeeded ? "true" : "false",GetCurrentTimeStamp(2).c_str()); //LOG("enableDoubleSensor QQQQQQQ:%s %s\n", m_config.params.doubleFeeded ? "true" : "false",GetCurrentTimeStamp(2).c_str());
if (m_DstScannum == 0) //被取消扫描了 if (m_DstScannum == 0) //被取消扫描了
{ {
LOG("canceled canceled canceled 999999999999999999999999999999999999999999 \n"); LOG("canceled canceled canceled 999999999999999999999999999999999999999999 \n");
@ -353,7 +343,7 @@ void Scanner::runScan()
LOG("\n ----------------EXIT 11111---------------- \n"); LOG("\n ----------------EXIT 11111---------------- \n");
break; break;
} }
LOG("\nclose double sensor %s\n",GetCurrentTimeStamp(2).c_str()); //LOG("\nclose double sensor %s\n",GetCurrentTimeStamp(2).c_str());
sensor->enableDoubleSensor(false); sensor->enableDoubleSensor(false);
if(b_autosize) if(b_autosize)
@ -406,7 +396,7 @@ void Scanner::runScan()
std::this_thread::yield(); std::this_thread::yield();
//printf("7777777777777777777777777777777777777\r\n");
this_thread::sleep_for(std::chrono::milliseconds(200)); this_thread::sleep_for(std::chrono::milliseconds(200));
} }
else else

View File

@ -145,6 +145,8 @@ void Sensor::monitor()
pfd.events = POLLPRI; pfd.events = POLLPRI;
StopWatch sw; StopWatch sw;
StopWatch sw1;
StopWatch sw2;
num = read(pfd.fd, buf, 8); // This is to clear the avaible read num = read(pfd.fd, buf, 8); // This is to clear the avaible read
std::cout<<"read time "<< sw.elapsed_ms()<<std::endl; std::cout<<"read time "<< sw.elapsed_ms()<<std::endl;
while (bMonitor) while (bMonitor)
@ -160,8 +162,19 @@ void Sensor::monitor()
buf[num - 1] = '\0'; buf[num - 1] = '\0';
ret = atoi(buf); ret = atoi(buf);
//ftt.append_log(ret?"in":"out"); //ftt.append_log(ret?"in":"out");
if (ret)
{
printf("检测纸张进入 time%f\r\n",sw2.elapsed_ms());
sw1.reset();
}else
{
printf("检测纸张出去 time%f\r\n",sw1.elapsed_ms());
sw2.reset();
}
edges[ret]->notify_all(); edges[ret]->notify_all();
LOG("\n *************scanpin %d time = %s ********* \n",ret,GetCurrentTimeStamp(2).c_str()); printf("\n *************scanpin %d time = %s ********* \n",ret,GetCurrentTimeStamp(2).c_str());
//sw.reset(); //sw.reset();
while(sw.elapsed_ms() < 10) while(sw.elapsed_ms() < 10)
{ {

View File

@ -293,7 +293,7 @@ struct V4L2_DATAINFO
struct V4L2_DATAINFO_Ex:V4L2_DATAINFO struct V4L2_DATAINFO_Ex:V4L2_DATAINFO
{ {
unsigned int snaped_index; unsigned int snaped_index;
unsigned int frame_index; //采集第几帧 unsigned int frame_index; //总帧数
unsigned int dpi; //dpi unsigned int dpi; //dpi
unsigned int error_code; unsigned int error_code;
unsigned int first_frame; //第一帧 unsigned int first_frame; //第一帧