608 lines
18 KiB
C++
608 lines
18 KiB
C++
|
#include <iostream>
|
|||
|
#include <memory>
|
|||
|
#include "stringex.hpp"
|
|||
|
#include <functional>
|
|||
|
#include "Capturer.h"
|
|||
|
#include "StopWatch.h"
|
|||
|
#include "opencv2/opencv.hpp"
|
|||
|
#include "config.h"
|
|||
|
#include "FpgaComm.h"
|
|||
|
#include "usbservice.h"
|
|||
|
#include "MonoCapturer.h"
|
|||
|
#include <fstream>
|
|||
|
#include "correct_ultis.h"
|
|||
|
#include "MultiFrameCapture.h"
|
|||
|
#include "MultiFrameCapture_8458Color.h"
|
|||
|
#include "MultiFrameCapture_8478_HL.h"
|
|||
|
#include "CImageMerge.h"
|
|||
|
|
|||
|
void get_system_output(char *cmd, char *output, int size)
|
|||
|
{
|
|||
|
FILE *fp = NULL;
|
|||
|
fp = popen(cmd, "r");
|
|||
|
if (fp)
|
|||
|
{
|
|||
|
if (fgets(output, size, fp) != NULL)
|
|||
|
{
|
|||
|
if (output[strlen(output) - 1] == '\n')
|
|||
|
output[strlen(output) - 1] = '\0';
|
|||
|
}
|
|||
|
pclose(fp);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
static void savebitmap(void *imgdata, int width, int height, bool color, std::string path)
|
|||
|
{
|
|||
|
cv::Mat mat;
|
|||
|
cv::Mat saveMat;
|
|||
|
std::vector<cv::Mat> ch_mats;
|
|||
|
int blockcnt = 12;
|
|||
|
int spitWidth = (width * 3) / blockcnt;
|
|||
|
int mergewidth = width / 4;
|
|||
|
mat = cv::Mat(height, width * 3, CV_8UC1, imgdata);
|
|||
|
cv::imwrite("gray" + path, mat);
|
|||
|
saveMat = cv::Mat(height, width, CV_8UC3);
|
|||
|
|
|||
|
StopWatch sw1;
|
|||
|
StopWatch sw;
|
|||
|
for (int i = 0; i < 4; i++)
|
|||
|
{
|
|||
|
sw.reset();
|
|||
|
for (int j = 0; j < 3; j++)
|
|||
|
ch_mats.push_back(mat(cv::Rect(spitWidth * (i * 3 + j), 0, spitWidth, height)));
|
|||
|
|
|||
|
std::cout << string_format("split: %d image elapsed:%f ms\n ", i, sw.elapsed_ms());
|
|||
|
|
|||
|
sw.reset();
|
|||
|
|
|||
|
// if(i == 0)
|
|||
|
// {
|
|||
|
// swap(ch_mats[0], ch_mats[2]);
|
|||
|
// swap(ch_mats[1], ch_mats[2]);
|
|||
|
// }
|
|||
|
|
|||
|
// if (i == 1)
|
|||
|
// {
|
|||
|
// swap(ch_mats[0], ch_mats[2]);
|
|||
|
// swap(ch_mats[1], ch_mats[0]);
|
|||
|
// }
|
|||
|
|
|||
|
if (i == 2)
|
|||
|
{
|
|||
|
swap(ch_mats[0], ch_mats[2]);
|
|||
|
}
|
|||
|
|
|||
|
if (i == 3)
|
|||
|
{
|
|||
|
swap(ch_mats[0], ch_mats[2]);
|
|||
|
}
|
|||
|
|
|||
|
cv::merge(ch_mats, saveMat(cv::Rect(mergewidth * i, 0, mergewidth, height)));
|
|||
|
std::cout << string_format("merge: %d image elapsed:%f ms\n ", i, sw.elapsed_ms());
|
|||
|
ch_mats.clear();
|
|||
|
}
|
|||
|
std::cout << string_format("merge image elapsed:%f ms\n ", sw1.elapsed_ms());
|
|||
|
cv::imwrite("merged" + path, saveMat);
|
|||
|
}
|
|||
|
|
|||
|
unsigned int delay_done(std::shared_ptr<IRegsAccess> regs, int ms)
|
|||
|
{
|
|||
|
unsigned int val;
|
|||
|
unsigned int reg8;
|
|||
|
regs->read(8, reg8);
|
|||
|
std::cout << "1 reg[8]:" << string_format("0x%08x", reg8) << std::endl;
|
|||
|
regs->write(8, reg8 | 0x8);
|
|||
|
std::cout << "sleep:" << ms << std::endl;
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
|||
|
regs->read(8, reg8);
|
|||
|
std::cout << "1 reg[8]:" << string_format("0x%08x", reg8) << std::endl;
|
|||
|
regs->read(14, val);
|
|||
|
int regv = val;
|
|||
|
val &= 0x0000ffff;
|
|||
|
std::cout << string_format("ONE height = %d reg[14] = %d \n", val, regv);
|
|||
|
regs->write(8, reg8 & 0xfffffff7);
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|||
|
regs->read(14, val);
|
|||
|
regv = val;
|
|||
|
val &= 0x0000ffff;
|
|||
|
regs->read(8, reg8);
|
|||
|
std::cout << "2 reg[8]:" << string_format("0x%08x", reg8) << std::endl;
|
|||
|
std::cout << string_format("TWO height = %d reg[14] = %d \n", val, regv);
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|||
|
regs->write(8, reg8 | 0x8);
|
|||
|
regs->read(8, reg8);
|
|||
|
std::cout << "2 reg[8]:" << string_format("0x%08x", reg8) << std::endl;
|
|||
|
return val;
|
|||
|
}
|
|||
|
|
|||
|
int delaytimes[] = {300, 400, 500, 600, 700, 800, 900, 1000,1200,1400,1600 };
|
|||
|
|
|||
|
int ws[] = {7344 / 2, 7344};
|
|||
|
|
|||
|
void list_regs(std::shared_ptr<IRegsAccess> regs)
|
|||
|
{
|
|||
|
unsigned int val = 0;
|
|||
|
for (int i = 5; i < 8; i++)
|
|||
|
{
|
|||
|
if (regs->read(i, val))
|
|||
|
std::cout << string_format("reg[%d] = 0x%08x\n", i, val);
|
|||
|
else
|
|||
|
std::cout << "read regs error " << std::endl;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// int main(int argc,char * argv[])
|
|||
|
// {
|
|||
|
// auto cap = std::shared_ptr<ICapturer>(new MonoCapturer());
|
|||
|
// StopWatch sw;
|
|||
|
// unsigned int val = 0;
|
|||
|
|
|||
|
// auto regs = cap->regs();
|
|||
|
// // UsbService us(regs, nullptr);
|
|||
|
// std::cout << " arg 1 color mode(0/1) arg2 dpi(2 300dpi 3 600dpi) "<<std::endl;
|
|||
|
// HGScanConfig config;
|
|||
|
// config.g200params.color = 1;
|
|||
|
// config.g200params.dpi = 2;
|
|||
|
// config.g200params.paper = (unsigned int)PaperSize::G400_A4;
|
|||
|
// if(argv[2])
|
|||
|
// config.g200params.dpi = atoi(argv[2])!=2?3:2;
|
|||
|
// else
|
|||
|
// config.g200params.dpi = 3;
|
|||
|
// if(argv[1])
|
|||
|
// config.g200params.color = atoi(argv[1])!=1?0:1;
|
|||
|
// else
|
|||
|
// config.g200params.color = 0;
|
|||
|
// void *data;
|
|||
|
// // cap->init_autocorrect(0);
|
|||
|
// FPGAConfigParam fpgaparam = GetFpgaparam(config.g200params.dpi, config.g200params.color);
|
|||
|
// cap->open(config,fpgaparam);
|
|||
|
// int ch = 0;
|
|||
|
// int ixx = 0;
|
|||
|
// // std::cout << "mod1:" << CV_8UC3 << " " << CV_8UC1 << std::endl;
|
|||
|
// for (int i = 0; i < 0x10; i++)
|
|||
|
// {
|
|||
|
// sw.reset();
|
|||
|
// if (regs->read(i, val))
|
|||
|
// std::cout << string_format("reg[%d] = 0x%08x\n", i, val);
|
|||
|
// else
|
|||
|
// std::cout << "read regs error " << std::endl;
|
|||
|
// }
|
|||
|
// std::cout << "type enter to grab" << std::endl;
|
|||
|
// int ix = 0;
|
|||
|
// int width = cap->width();
|
|||
|
// int fixedheight = cap->height();
|
|||
|
// int type = cap->color();
|
|||
|
// int height = fixedheight;
|
|||
|
// if (type == CV_8UC3)
|
|||
|
// {
|
|||
|
// height = fixedheight / 3;
|
|||
|
// width = width * 2 * 3 * 3;
|
|||
|
// type = CV_8UC1;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// height = fixedheight;
|
|||
|
// width = width * 2 * 3;
|
|||
|
// }
|
|||
|
// while ((ch = getchar()) != 'q')
|
|||
|
// {
|
|||
|
// #ifdef LOOP_DEBUG
|
|||
|
// for (int i = 0; i < 2000; i++)
|
|||
|
// #endif
|
|||
|
// {
|
|||
|
// ix++;
|
|||
|
// // sw.reset();
|
|||
|
// // for (int j = 0; j < 15; j++)
|
|||
|
// // {
|
|||
|
// // sw.reset();
|
|||
|
// // if (regs->read(j, val))
|
|||
|
// // std::cout << string_format("reg[%d] = 0x%08x, %f\n", j, val, sw.elapsed_ms());
|
|||
|
// // else
|
|||
|
// // std::cout << "read regs error " << std::endl;
|
|||
|
// // }
|
|||
|
// sw.reset();
|
|||
|
// cap->snap();
|
|||
|
// #ifdef LOOP_DEBUG
|
|||
|
// height = delay_done(regs, delaytimes[ix % (sizeof(delaytimes) / sizeof(delaytimes[0]))]);
|
|||
|
// std::cout << string_format("%dth grab time height = %d", ix, height) << std::endl;
|
|||
|
// height = std::min(fixedheight, height);
|
|||
|
// #endif
|
|||
|
// if (data = cap->readFrame(5000))
|
|||
|
// {
|
|||
|
// // for (int i = 0; i < 0x10; i++)
|
|||
|
// // {
|
|||
|
// // sw.reset();
|
|||
|
// // if (regs->read(i, val))
|
|||
|
// // std::cout << string_format("readFrame reg[%d] = 0x%08x\n", i, val);
|
|||
|
// // else
|
|||
|
// // std::cout << "read regs error " << std::endl;
|
|||
|
// // }
|
|||
|
// // std::cout << string_format("QQQQQQQQ %dth grab time height = %d: %fms", ix, height, sw.elapsed_ms()) << std::endl;
|
|||
|
// std::cout << string_format("grab time width = %d, height = %d, type = %d: %fms", width, height, type, sw.elapsed_ms()) << std::endl;
|
|||
|
// sw.reset();
|
|||
|
// int channel = cap->color() == 16 ? 3 : 1;
|
|||
|
// int dstwith = cap->width() * 2 * 3;
|
|||
|
// int dstHeight = height;
|
|||
|
// cv::Mat mat(dstHeight, dstwith * channel, CV_8UC1, data);
|
|||
|
// static int testindex = 0;
|
|||
|
// //cv::imwrite(std::to_string(++testindex) + std::to_string(dstHeight) + "autosizeorg.jpg", mat);
|
|||
|
// //if(channel == 3)
|
|||
|
// {
|
|||
|
// CImageMerge mrg;
|
|||
|
// auto retmat = mrg.MergeImage(channel == 3, mat, dstwith , dstHeight,0x9000a);
|
|||
|
// cv::imwrite(std::to_string(++testindex) + std::to_string(dstHeight) + "mergeorg.jpg", retmat);
|
|||
|
// }
|
|||
|
// #ifndef LOOP_DEBUG
|
|||
|
// // cv::Mat mat=GetMergeMat(data,cap->width(),cap->height(),cap->color());
|
|||
|
// // mat = cv::Mat(height, width, type, data);
|
|||
|
// // cv::imwrite( std::to_string(ix++)+ ".jpg", mat);
|
|||
|
// // std::cout << string_format("%dth grab time height = %d: %fms", ix, height, sw.elapsed_ms()) << std::endl;
|
|||
|
// // sw.reset();
|
|||
|
// // savebitmap(data, width, height, true, std::to_string(ix) + ".jpg");
|
|||
|
// // std::cout << string_format("%dth grab save time : %fms", ix, sw.elapsed_ms()) << std::endl;
|
|||
|
// // sw.reset();
|
|||
|
// // memset(data, 0, width * height * 3);
|
|||
|
// // std::cout << string_format("%dth memset time : %fms", ix, sw.elapsed_ms()) << std::endl;
|
|||
|
// #endif
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// std::cout << "error :" << ix << std::endl;
|
|||
|
// #ifdef LOOP_DEBUG
|
|||
|
// break;
|
|||
|
// #endif
|
|||
|
// }
|
|||
|
// }
|
|||
|
// std::cout << "type enter to continue" << std::endl;
|
|||
|
// }
|
|||
|
// return 0;
|
|||
|
// }
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#if 0
|
|||
|
int main(int argc,char * argv[]){
|
|||
|
system("mkdir /root/vsp");
|
|||
|
auto cap = std::shared_ptr<ICapturer>(new MonoCapturer());
|
|||
|
HGScanConfig config{0};
|
|||
|
config.g200params.color = 1;
|
|||
|
config.g200params.dpi = 1;
|
|||
|
config.g200params.paper = (unsigned int)PaperSize::G400_A4R;
|
|||
|
// std::vector<HGScanConfig> c_v;
|
|||
|
// for(int i=1;i<4;i++)
|
|||
|
// for(int j =0;j<2;j++)
|
|||
|
// {
|
|||
|
// config.g200params.dpi = i;
|
|||
|
// config.g200params.color = j;
|
|||
|
// c_v.push_back(config);
|
|||
|
// }
|
|||
|
uint64_t index_ =0;
|
|||
|
uint64_t cf_i =0;
|
|||
|
void * data;
|
|||
|
int height; //
|
|||
|
std::cout << "capture open" << std::endl;
|
|||
|
//while(1)
|
|||
|
{
|
|||
|
FPGAConfigParam fpgaparam = GetFpgaparam(config.g200params.dpi, config.g200params.color);
|
|||
|
cap->open(config,fpgaparam);
|
|||
|
cap->getautosizeheight();
|
|||
|
for(int i =0;i <512;i++){
|
|||
|
//config = c_v[i];
|
|||
|
//std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|||
|
|
|||
|
cap->set_fpga_vsp(i,i);
|
|||
|
|
|||
|
|
|||
|
cap->snap();
|
|||
|
std::cout << "capture snap" << std::endl;
|
|||
|
height = cap->height();
|
|||
|
data = cap->readFrame(7000);
|
|||
|
if(data){
|
|||
|
std::cout << "capture ReadMultiFrame" << std::endl;
|
|||
|
int channel = cap->color() == 16 ? 3 : 1;
|
|||
|
int dstwith = cap->width() * 2 * 3 * channel;
|
|||
|
int dstHeight = config.g200params.paper == (unsigned int)PaperSize::G400_AUTO ? height : height / channel;
|
|||
|
cv::Mat mat(dstHeight, dstwith, CV_8UC1, data);
|
|||
|
int dstwidth = config.g200params.color == 0 ?dstwith:dstwith/3;
|
|||
|
|
|||
|
cv::Mat dst = GetMergeMat(dstwidth, dstHeight, config.g200params.color == 0 ? 0:16,mat,0x9000c);
|
|||
|
//correctColor(dst,config.g200params.dpi,dst.channels()==3?1:0,false);
|
|||
|
//cv::imwrite("/root/vsp30/dpi_"+std::to_string(config.g200params.dpi)+"_mode_"+std::to_string(dst.channels()==3?1:0)+".bmp",dst);
|
|||
|
//i++;
|
|||
|
cv::imwrite("/root/vsp/"+std::to_string(i)+".jpg",dst);
|
|||
|
std::cout << "capture end index "<< index_ << " vsp = "<< i <<std::endl;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
std::cout << "capture error" << std::endl;
|
|||
|
}
|
|||
|
index_++;
|
|||
|
|
|||
|
}
|
|||
|
cap->close();
|
|||
|
cf_i++;
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
#if 0
|
|||
|
|
|||
|
int main(int argc,char * argv[]){
|
|||
|
system("mkdir /root/vsp");
|
|||
|
system("mkdir /root/vsp/A");
|
|||
|
system("mkdir /root/vsp/B");
|
|||
|
auto cap = std::shared_ptr<ICapturer>(new MonoCapturer());
|
|||
|
HGScanConfig config{0};
|
|||
|
config.g200params.color = 1;
|
|||
|
config.g200params.dpi = 1;
|
|||
|
config.g200params.paper = (unsigned int)PaperSize::G400_A4R;
|
|||
|
uint64_t index_ =0;
|
|||
|
uint64_t cf_i =0;
|
|||
|
void * data;
|
|||
|
int height; //
|
|||
|
std::cout << "capture open" << std::endl;
|
|||
|
//while(1)
|
|||
|
{
|
|||
|
FPGAConfigParam fpgaparam = GetFpgaparam(config.g200params.dpi, config.g200params.color);
|
|||
|
cap->open(config,fpgaparam);
|
|||
|
cap->getautosizeheight();
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|||
|
for(int i =0;i <512;i++){
|
|||
|
cap->set_fpga_vsp(i,i);
|
|||
|
cap->snap();
|
|||
|
std::cout << "capture snap" << std::endl;
|
|||
|
height = cap->height();
|
|||
|
std::cout << "capture ReadMultiFrame" << std::endl;
|
|||
|
data = cap->readFrame(7000);
|
|||
|
if(data){
|
|||
|
int channel = cap->color() == 16 ? 3 : 1;
|
|||
|
int dstwith = cap->width() * 2 * 3 * channel;
|
|||
|
int dstHeight = config.g200params.paper == (unsigned int)PaperSize::G400_AUTO ? height : height / channel;
|
|||
|
cv::Mat mat(dstHeight, dstwith, CV_8UC1, data);
|
|||
|
int dstwidth = config.g200params.color == 0 ?dstwith:dstwith/3;
|
|||
|
cv::Mat dst = GetMergeMat(dstwidth, dstHeight, config.g200params.color == 0 ? 0:16,mat,0x900a1);
|
|||
|
cv::imwrite("/root/vsp/A/"+std::to_string(i)+".bmp",dst(cv::Rect(0,0,dst.cols/2,dst.rows)));
|
|||
|
cv::imwrite("/root/vsp/B/"+std::to_string(i)+".bmp",dst(cv::Rect(dst.cols/2,0,dst.cols/2,dst.rows)));
|
|||
|
std::cout << "capture end index "<< index_ << " vsp = "<< i <<std::endl;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
std::cout << "capture error" << std::endl;
|
|||
|
}
|
|||
|
index_++;
|
|||
|
}
|
|||
|
cap->close();
|
|||
|
cf_i++;
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|
|||
|
void write_reg(int addr,int bank,int val,std::shared_ptr<IRegsAccess> reg,bool is_a)
|
|||
|
{
|
|||
|
union reg_str
|
|||
|
{
|
|||
|
struct
|
|||
|
{
|
|||
|
uint32_t val_l : 8;
|
|||
|
uint32_t addr_l : 6;
|
|||
|
uint32_t r_or_w_l :2;
|
|||
|
uint32_t val_h : 8;
|
|||
|
uint32_t addr_h : 6;
|
|||
|
uint32_t r_or_w_h :2;
|
|||
|
}adc;
|
|||
|
uint32_t value;
|
|||
|
};
|
|||
|
reg_str reg_w{0};
|
|||
|
reg_w.adc.r_or_w_h = reg_w.adc.r_or_w_l = 0;
|
|||
|
reg_w.adc.addr_l = 0;
|
|||
|
reg_w.adc.addr_h = addr;
|
|||
|
reg_w.adc.val_l = bank;
|
|||
|
reg_w.adc.val_h = val;
|
|||
|
reg->write(is_a ?4:7,reg_w.value);
|
|||
|
uint32_t reg1_v;
|
|||
|
reg->read(1,reg1_v);
|
|||
|
Mode_FPGA reg1 = *((Mode_FPGA*)®1_v);
|
|||
|
is_a ? reg1.adcA = 1 :reg1.adcB = 1 ;
|
|||
|
reg->write(1,*((uint32_t*)®1));
|
|||
|
is_a ? reg1.adcA = 0 :reg1.adcB = 0 ;
|
|||
|
reg->write(1,*((uint32_t*)®1));
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|||
|
std::cout<<std::hex<<"write 0x"<<reg_w.value<<std::endl;
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// uint32_t read_reg(int addr,int bank,std::shared_ptr<IRegsAccess> reg)
|
|||
|
// {
|
|||
|
// union reg_str
|
|||
|
// {
|
|||
|
// struct
|
|||
|
// {
|
|||
|
// uint32_t val_l : 8;
|
|||
|
// uint32_t addr_l : 6;
|
|||
|
// uint32_t r_or_w_l :2;
|
|||
|
// uint32_t val_h : 8;
|
|||
|
// uint32_t addr_h : 6;
|
|||
|
// uint32_t r_or_w_h :2;
|
|||
|
// }adc;
|
|||
|
// uint32_t value;
|
|||
|
// };
|
|||
|
// reg_str reg_w{0};
|
|||
|
// reg_w.adc.r_or_w_h = 3;
|
|||
|
// reg_w.adc.r_or_w_l = 1;
|
|||
|
// reg_w.adc.addr_l = 0;
|
|||
|
// reg_w.adc.addr_h = addr;
|
|||
|
// reg_w.adc.val_l = bank;
|
|||
|
// reg_w.adc.val_h = 0;
|
|||
|
// reg->write(4,reg_w.value);
|
|||
|
// uint32_t reg1_v;
|
|||
|
// reg->read(1,reg1_v);
|
|||
|
// Mode_FPGA reg1 = *((Mode_FPGA*)®1_v);
|
|||
|
// reg1.adcA = 1;
|
|||
|
// reg->write(1,*((uint32_t*)®1));
|
|||
|
// reg1.adcA = 0;
|
|||
|
// reg->write(1,*((uint32_t*)®1));
|
|||
|
// uint32_t read_reg =0;
|
|||
|
// reg->read(3,read_reg);
|
|||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|||
|
// return read_reg;
|
|||
|
// }
|
|||
|
|
|||
|
uint32_t read_reg(int addr,int bank,std::shared_ptr<IRegsAccess> reg,bool is_a)
|
|||
|
{
|
|||
|
union reg_str
|
|||
|
{
|
|||
|
struct
|
|||
|
{
|
|||
|
uint32_t val_l : 8;
|
|||
|
uint32_t addr_l : 6;
|
|||
|
uint32_t r_or_w_l :2;
|
|||
|
uint32_t val_h : 8;
|
|||
|
uint32_t addr_h : 6;
|
|||
|
uint32_t r_or_w_h :2;
|
|||
|
}adc;
|
|||
|
uint32_t value;
|
|||
|
};
|
|||
|
reg_str reg_w{0};
|
|||
|
reg_w.adc.r_or_w_h = 2;
|
|||
|
reg_w.adc.r_or_w_l = 2;
|
|||
|
reg_w.adc.addr_l = addr+1;
|
|||
|
reg_w.adc.addr_h = addr;
|
|||
|
reg_w.adc.val_l = 0;
|
|||
|
reg_w.adc.val_h = 0;
|
|||
|
reg->write(is_a ? 4 : 7,reg_w.value);
|
|||
|
uint32_t reg1_v;
|
|||
|
reg->read(1,reg1_v);
|
|||
|
Mode_FPGA reg1 = *((Mode_FPGA*)®1_v);
|
|||
|
is_a ? reg1.adcA = 1 :reg1.adcB = 1 ;
|
|||
|
reg->write(1,*((uint32_t*)®1));
|
|||
|
|
|||
|
is_a ? reg1.adcA = 0 :reg1.adcB = 0 ;
|
|||
|
reg->write(1,*((uint32_t*)®1));
|
|||
|
uint32_t read_reg =0;
|
|||
|
reg->read(3,read_reg);
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|||
|
return read_reg;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
const uint8_t bank_change[4] = {0x15,0x35,0x55,0x75};
|
|||
|
|
|||
|
int main(int argc,char *argv[])
|
|||
|
{
|
|||
|
if(argc != 3)
|
|||
|
{
|
|||
|
std::cout<< "输入参数错误 ! "<<std::endl;
|
|||
|
std::cout<< " 1 -> 200dpi 2 -> 300dpi 3 -> 600dpi "<<std::endl;
|
|||
|
std::cout<< " 0 -> gray 1 -> color "<<std::endl;
|
|||
|
std::cout<< "例如:./testcapimage 2 1 300dpi 彩色 "<<std::endl;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
// auto cap = std::shared_ptr<MultiFrameCapture>(new MultiFrameCapture());
|
|||
|
auto cap = std::shared_ptr<MultiFrameCapture_8478_HL>(new MultiFrameCapture_8478_HL());
|
|||
|
StopWatch sw;
|
|||
|
unsigned int val = 0;
|
|||
|
auto regs = cap->regs();
|
|||
|
uint32_t reg4 = 0,reg2= 0;
|
|||
|
|
|||
|
// return 1;
|
|||
|
system("mkdir /root/img");
|
|||
|
regs->read(2,reg2);
|
|||
|
regs->write(2,(reg2&0xffffffe1)|0xc); // adc <20><><EFBFBD><EFBFBD> Ƶ<><C6B5>
|
|||
|
|
|||
|
// cap->init_autocorrect(0);
|
|||
|
// std::this_thread::sleep_for(std::chrono::minutes(1));
|
|||
|
// return 0;
|
|||
|
|
|||
|
uint32_t index =0;
|
|||
|
// while ((ch = getchar()) != 'q')
|
|||
|
{
|
|||
|
uint dpi_ = atoi(argv[1]);
|
|||
|
uint mode_ = atoi(argv[2]);
|
|||
|
std::cout << "mode = " << mode_<<" dpi = "<<dpi_;
|
|||
|
if((dpi_ > 3) || (dpi_ < 1))
|
|||
|
dpi_ = 1;
|
|||
|
if((mode_ > 1) || (mode_ < 0))
|
|||
|
mode_ = 1;
|
|||
|
HGScanConfig config;
|
|||
|
config.g200params.color = mode_;
|
|||
|
config.g200params.dpi = dpi_;
|
|||
|
config.g200params.paper = (unsigned int)PaperSize::G400_MAXSIZE;
|
|||
|
void *data = nullptr;
|
|||
|
// cap->init_autocorrect(0);
|
|||
|
FPGAConfigParam_8478 fpgaparam = CorrectParam().GetFpgaparam_8478(config.g200params.dpi, config.g200params.color);
|
|||
|
// FPGAConfigParam fpgaparam = Get_Static_CorrectParam().GetFpgaparam(config.g200params.dpi,config.g200params.color);
|
|||
|
unsigned int fpgaversion,reg11;
|
|||
|
//fpgaparam.Sp = 4680;
|
|||
|
printf(" ----- set SP = %d ----\n",fpgaparam.Sp);
|
|||
|
cap->open(config,fpgaparam);
|
|||
|
// cap->write_adc_8478(bank_change[0],0x22,0x8A,true);
|
|||
|
// cap->write_adc_8478(bank_change[0],0x22,0x8A,false);
|
|||
|
cap->init_imagedatabuffer();
|
|||
|
uint32_t reg4 = 0;
|
|||
|
regs->read(5,reg4);
|
|||
|
regs->write(5,reg4|0xc000);
|
|||
|
|
|||
|
regs->read(15, fpgaversion);
|
|||
|
std::cout <<std::hex<<"fpgaversion:0x" << fpgaversion << std::endl;
|
|||
|
int ix = 0;
|
|||
|
|
|||
|
//bos cl1 cl0 en ch
|
|||
|
for (size_t i = 0;i < 6 ;i++)
|
|||
|
//for (size_t i = 0; ;i++)
|
|||
|
{
|
|||
|
// config.g200params.dpi = i%3+1;
|
|||
|
// config.g200params.color = i<3;
|
|||
|
//cap->open(config,CorrectParam().GetFpgaparam_8478(i%3+1,i<3));
|
|||
|
|
|||
|
sw.reset();
|
|||
|
cap->snap();
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(rand()%400+100));
|
|||
|
auto buf = cap->ReadMultiFrame(1);
|
|||
|
regs->read(20, fpgaversion);
|
|||
|
std::cout <<std::hex<<" reg 20 :0x" << fpgaversion << std::endl;
|
|||
|
int ix = 0;
|
|||
|
if(buf.offset)
|
|||
|
//if (data = cap->readFrame(5000))
|
|||
|
{
|
|||
|
std::cout << "get data size buf.offset :" << buf.offset << std::endl;
|
|||
|
size_t width_mat = cap->width()*(config.g200params.color == 1 ? 3:1)*2;
|
|||
|
std::cout << "get img width : " << width_mat << " \t img height : " << buf.img_h << "\n";
|
|||
|
cv::Mat mat(buf.img_h,width_mat,CV_8UC1,buf.pdata);
|
|||
|
// cv::imwrite("/root/img/"+std::to_string(i)+"BRG.bmp",mat);
|
|||
|
|
|||
|
auto merge = cap->merge_8478(mat,config.g200params.color,0);
|
|||
|
cv::imwrite("/root/img/"+std::to_string(i)+"merge.bmp",merge);
|
|||
|
|
|||
|
// cv::Mat mat_rgb(buf.img_h*3,width_mat/3,CV_8UC1,buf.pdata);
|
|||
|
// cv::imwrite("/root/img/"+std::to_string(i)+"src.bmp",mat_rgb);
|
|||
|
//std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|||
|
|
|||
|
// double max,min;
|
|||
|
// cv::Point maxidx,minidx;
|
|||
|
// cv::minMaxLoc(mat(cv::Rect(mat.cols /2 + 10,0,mat.cols /2 - 10 ,mat.rows)),&min,&max,&minidx,&maxidx);
|
|||
|
// std::cout << "B___" << " min = " << min <<" max = " << max << " min <20><><EFBFBD><EFBFBD> = " << minidx<< " max <20><><EFBFBD><EFBFBD> = " << maxidx <<" index = " << i <<std::endl;
|
|||
|
// if(max != 0xaa)
|
|||
|
// {
|
|||
|
// cv::imwrite("/root/"+std::to_string(i) +"_.jpg",mat);
|
|||
|
// }
|
|||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|||
|
std::cout << "success :" <<std::dec << i << std::endl;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
std::cout << "error :" << i << std::endl;
|
|||
|
}
|
|||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|||
|
//cap->close();
|
|||
|
}
|
|||
|
cap->close();
|
|||
|
cap->free_imagedatabuffer();
|
|||
|
}
|
|||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|