调整整体出图流程

This commit is contained in:
modehua 2023-07-19 20:48:38 -07:00
parent fbf727e3e9
commit 0634448af9
12 changed files with 546 additions and 449 deletions

View File

@ -1,140 +1,140 @@
// #include "CImageMerge.h"
// #include <sstream>
#include "CImageMerge.h"
#include <sstream>
// CImageMerge::CImageMerge()
// {
// }
// CImageMerge::~CImageMerge()
// {
// }
CImageMerge::CImageMerge()
{
}
CImageMerge::~CImageMerge()
{
}
// cv::Mat CImageMerge::MergeImage(cv::Mat &srcMat, int dstwidth, int dstheight,int mode)
// {
// cv::Mat dst(srcMat.rows, srcMat.cols / (mode == 0 ? 1:3), CV_8UC(mode == 0 ? 1 : 3));
// auto graymerge = [](cv::Mat& src,cv::Mat dst)->cv::Mat{
// int width_block = src.cols / 12;
// int heigh_block = src.rows;
cv::Mat CImageMerge::MergeImage(cv::Mat &srcMat, int dstwidth, int dstheight,int mode)
{
cv::Mat dst(srcMat.rows, srcMat.cols / (mode == 0 ? 1:3), CV_8UC(mode == 0 ? 1 : 3));
auto graymerge = [](cv::Mat& src,cv::Mat dst)->cv::Mat{
int width_block = src.cols / 12;
int heigh_block = src.rows;
// // 20 vsp 拼接算法
// // src(cv::Rect(width_block,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(0,0,width_block*2,heigh_block)));
// // src(cv::Rect(0,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*2,0,width_block,heigh_block)));
// // src(cv::Rect(width_block*3,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*4,0,width_block*2,heigh_block)));
// // src(cv::Rect(width_block*5,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*3,0,width_block,heigh_block)));
// 20 vsp 拼接算法
// src(cv::Rect(width_block,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(0,0,width_block*2,heigh_block)));
// src(cv::Rect(0,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*2,0,width_block,heigh_block)));
// src(cv::Rect(width_block*3,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*4,0,width_block*2,heigh_block)));
// src(cv::Rect(width_block*5,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*3,0,width_block,heigh_block)));
// // src(cv::Rect(width_block*7,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*6,0,width_block*2,heigh_block)));
// // src(cv::Rect(width_block*6,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*8,0,width_block,heigh_block)));
// // src(cv::Rect(width_block*9,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*10,0,width_block*2,heigh_block)));
// // src(cv::Rect(width_block*11,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*9,0,width_block,heigh_block)));
// //return dst;
// src(cv::Rect(width_block*7,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*6,0,width_block*2,heigh_block)));
// src(cv::Rect(width_block*6,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*8,0,width_block,heigh_block)));
// src(cv::Rect(width_block*9,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*10,0,width_block*2,heigh_block)));
// src(cv::Rect(width_block*11,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*9,0,width_block,heigh_block)));
//return dst;
// // 45 vsp 拼接算法
// src(cv::Rect(0,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block,0,width_block*2,heigh_block)));
// src(cv::Rect(width_block*2,0,width_block,heigh_block)).copyTo(dst(cv::Rect(0,0,width_block,heigh_block)));
// src(cv::Rect(width_block*3,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*5,0,width_block,heigh_block)));
// src(cv::Rect(width_block*4,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*3,0,width_block*2,heigh_block)));
// 45 vsp 拼接算法
src(cv::Rect(0,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block,0,width_block*2,heigh_block)));
src(cv::Rect(width_block*2,0,width_block,heigh_block)).copyTo(dst(cv::Rect(0,0,width_block,heigh_block)));
src(cv::Rect(width_block*3,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*5,0,width_block,heigh_block)));
src(cv::Rect(width_block*4,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*3,0,width_block*2,heigh_block)));
// src(cv::Rect(width_block*6,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*7,0,width_block*2,heigh_block)));
// src(cv::Rect(width_block*8,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*6,0,width_block,heigh_block)));
// src(cv::Rect(width_block*9,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*11,0,width_block,heigh_block)));
// src(cv::Rect(width_block*10,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*9,0,width_block*2,heigh_block)));
// return dst;
src(cv::Rect(width_block*6,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*7,0,width_block*2,heigh_block)));
src(cv::Rect(width_block*8,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*6,0,width_block,heigh_block)));
src(cv::Rect(width_block*9,0,width_block,heigh_block)).copyTo(dst(cv::Rect(width_block*11,0,width_block,heigh_block)));
src(cv::Rect(width_block*10,0,width_block*2,heigh_block)).copyTo(dst(cv::Rect(width_block*9,0,width_block*2,heigh_block)));
return dst;
// };
// //cv::imwrite("org.jpg",srcMat);
// if (!srcMat.empty())
// {
// if(mode == 0)//灰度模式
// return graymerge(srcMat,dst);
};
//cv::imwrite("org.jpg",srcMat);
if (!srcMat.empty())
{
if(mode == 0)//灰度模式
return graymerge(srcMat,dst);
// std::vector<cv::Mat> ch_mats;
// int blockcnt = 12;
// int spitWidth = srcMat.cols / blockcnt;
// cv::Mat retMat(srcMat.rows, srcMat.cols / 3, CV_8UC3);
// for (int i = 0; i < 4; i++)
// {
// if (i < 2)
// {
// ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 1), 0, spitWidth, srcMat.rows)));
// ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 2), 0, spitWidth, srcMat.rows)));
// ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 0), 0, spitWidth, srcMat.rows)));
// }
// else
// {
// ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 1), 0, spitWidth, srcMat.rows)));
// ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 0), 0, spitWidth, srcMat.rows)));
// ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 2), 0, spitWidth, srcMat.rows)));
// }
// cv::merge(ch_mats, retMat(cv::Rect(spitWidth * i, 0, spitWidth, srcMat.rows)));
// ch_mats.clear();
// }
// return graymerge(retMat,dst);
// }
// return srcMat;
// }
std::vector<cv::Mat> ch_mats;
int blockcnt = 12;
int spitWidth = srcMat.cols / blockcnt;
cv::Mat retMat(srcMat.rows, srcMat.cols / 3, CV_8UC3);
for (int i = 0; i < 4; i++)
{
if (i < 2)
{
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 1), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 2), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 0), 0, spitWidth, srcMat.rows)));
}
else
{
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 1), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 0), 0, spitWidth, srcMat.rows)));
ch_mats.push_back(srcMat(cv::Rect(spitWidth * (i * 3 + 2), 0, spitWidth, srcMat.rows)));
}
cv::merge(ch_mats, retMat(cv::Rect(spitWidth * i, 0, spitWidth, srcMat.rows)));
ch_mats.clear();
}
return graymerge(retMat,dst);
}
return srcMat;
}
// cv::Mat CImageMerge::MergeImage(bool iscolor, cv::Mat &srcMat, int dstwidth, int dstheight)
// {
// int blockcnt = 12;
// int spitWidth = srcMat.cols / blockcnt;
// int abortwidth; // = spitWidth == 3888 ? 432 : (spitWidth == 2592 ? 216 : 144);
// if (!iscolor) // 灰度
// {
// abortwidth = spitWidth == 1296 ? 432 : (spitWidth == 648 ? 216 : 144);
// }
// else
// {
// abortwidth = spitWidth == 3888 ? 432 : (spitWidth == 1944 ? 216 : 144);
// }
cv::Mat CImageMerge::MergeImage(bool iscolor, cv::Mat &srcMat, int dstwidth, int dstheight)
{
int blockcnt = 12;
int spitWidth = srcMat.cols / blockcnt;
int abortwidth; // = spitWidth == 3888 ? 432 : (spitWidth == 2592 ? 216 : 144);
if (!iscolor) // 灰度
{
abortwidth = spitWidth == 1296 ? 432 : (spitWidth == 648 ? 216 : 144);
}
else
{
abortwidth = spitWidth == 3888 ? 432 : (spitWidth == 1944 ? 216 : 144);
}
// cv::Mat dst(dstheight, dstwidth - abortwidth * 2, CV_8UC(iscolor ? 3 : 1));
// if (!iscolor)
// {
// for (int i = 0; i < 2; i++)
// {
// srcMat(cv::Rect((dstwidth / 2 + abortwidth) * i, 0, dstwidth / 2 - abortwidth, dstheight)).copyTo(dst(cv::Rect(dst.cols / 2 * i, 0, dst.cols / 2, dstheight)));
// }
// srcMat.release();
// return dst;
// }
// else
// {
// std::vector<cv::Mat> m_splits;
// std::vector<int> m_index = {1, 4, 7, 10, 2, 5, 6, 9, 0, 3, 8, 11};
cv::Mat dst(dstheight, dstwidth - abortwidth * 2, CV_8UC(iscolor ? 3 : 1));
if (!iscolor)
{
for (int i = 0; i < 2; i++)
{
srcMat(cv::Rect((dstwidth / 2 + abortwidth) * i, 0, dstwidth / 2 - abortwidth, dstheight)).copyTo(dst(cv::Rect(dst.cols / 2 * i, 0, dst.cols / 2, dstheight)));
}
srcMat.release();
return dst;
}
else
{
std::vector<cv::Mat> m_splits;
std::vector<int> m_index = {1, 4, 7, 10, 2, 5, 6, 9, 0, 3, 8, 11};
// for (int i = 0; i < 3; i++)
// {
// int startindex = i == 0 ? 0 : (i == 1 ? 4 : 8);
// cv::Mat t_mat(dstheight, dstwidth - abortwidth * 2, CV_8UC1);
// srcMat(cv::Rect(spitWidth * m_index[startindex + 0], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(0, 0, spitWidth, dstheight)));
// srcMat(cv::Rect(spitWidth * m_index[startindex + 1], 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth, 0, spitWidth - abortwidth, dstheight)));
// srcMat(cv::Rect(spitWidth * m_index[startindex + 2] + abortwidth, 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 2 - abortwidth, 0, spitWidth - abortwidth, dstheight)));
// srcMat(cv::Rect(spitWidth * m_index[startindex + 3], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 3 - abortwidth * 2, 0, spitWidth, dstheight)));
// m_splits.push_back(t_mat);
// }
// cv::merge(m_splits, dst);
// m_splits.clear();
// }
// srcMat.release();
// return dst;
// }
for (int i = 0; i < 3; i++)
{
int startindex = i == 0 ? 0 : (i == 1 ? 4 : 8);
cv::Mat t_mat(dstheight, dstwidth - abortwidth * 2, CV_8UC1);
srcMat(cv::Rect(spitWidth * m_index[startindex + 0], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(0, 0, spitWidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 1], 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth, 0, spitWidth - abortwidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 2] + abortwidth, 0, spitWidth - abortwidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 2 - abortwidth, 0, spitWidth - abortwidth, dstheight)));
srcMat(cv::Rect(spitWidth * m_index[startindex + 3], 0, spitWidth, dstheight)).copyTo(t_mat(cv::Rect(spitWidth * 3 - abortwidth * 2, 0, spitWidth, dstheight)));
m_splits.push_back(t_mat);
}
cv::merge(m_splits, dst);
m_splits.clear();
}
srcMat.release();
return dst;
}
// cv::Mat CImageMerge::MergeFrames(std::vector<cv::Mat> frames, int type, int dpi)
// {
// if (frames.empty())
// return cv::Mat();
cv::Mat CImageMerge::MergeFrames(std::vector<cv::Mat> frames, int type, int dpi)
{
if (frames.empty())
return cv::Mat();
// int size = frames.size();
// auto it = frames.begin();
// int dstH = it->rows * size;
// int abortwidth = dpi == 0x02 || dpi == 0x01 ? 432 : 864; // 216*2 432*2
// int dstwidth = dpi == 0x02 || dpi == 0x01 ? 7344 : 14688;
// cv::Mat matdst(dstH, dstwidth, CV_8UC(type == 1 ? 3 : 1));
// for (int i = 0; i < size; i++)
// {
// auto itemimg = frames[i];
// itemimg = MergeImage(type, itemimg, dstwidth + abortwidth, itemimg.rows);
// itemimg.copyTo(matdst(cv::Rect(0, itemimg.rows * i, itemimg.cols, itemimg.rows)));
// itemimg.release();
// }
// return matdst;
// }
int size = frames.size();
auto it = frames.begin();
int dstH = it->rows * size;
int abortwidth = dpi == 0x02 || dpi == 0x01 ? 432 : 864; // 216*2 432*2
int dstwidth = dpi == 0x02 || dpi == 0x01 ? 7344 : 14688;
cv::Mat matdst(dstH, dstwidth, CV_8UC(type == 1 ? 3 : 1));
for (int i = 0; i < size; i++)
{
auto itemimg = frames[i];
itemimg = MergeImage(type, itemimg, dstwidth + abortwidth, itemimg.rows);
itemimg.copyTo(matdst(cv::Rect(0, itemimg.rows * i, itemimg.cols, itemimg.rows)));
itemimg.release();
}
return matdst;
}

View File

@ -1,15 +1,15 @@
// #pragma once
// #include <opencv2/opencv.hpp>
#pragma once
#include <opencv2/opencv.hpp>
// class CImageMerge
// {
// private:
// /* data */
// public:
// CImageMerge(/* args */);
// ~CImageMerge();
// public:
// cv::Mat MergeImage(cv::Mat& srcMat,int dstwidth,int dstheight,int mode);
// cv::Mat MergeImage(bool iscolor,cv::Mat& srcMat,int dstwidth,int dstheight);
// cv::Mat MergeFrames(std::vector<cv::Mat> frames, int type, int dpi);
// };
class CImageMerge
{
private:
/* data */
public:
CImageMerge(/* args */);
~CImageMerge();
public:
cv::Mat MergeImage(cv::Mat& srcMat,int dstwidth,int dstheight,int mode);
cv::Mat MergeImage(bool iscolor,cv::Mat& srcMat,int dstwidth,int dstheight);
cv::Mat MergeFrames(std::vector<cv::Mat> frames, int type, int dpi);
};

View File

@ -127,6 +127,7 @@ int HCamDevice::close_video()
}
close(videofd);
HtCamStopSampling();
HtCamExitVideoCapturing();
camera_dbg("close video succeed\n");
return 0;
}
@ -243,13 +244,14 @@ void HCamDevice::HtCamStopVideoCapturing()
type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
else
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (ioctl(videofd, VIDIOC_STREAMOFF, &type) == -1)
camera_err(" VIDIOC_STREAMOFF error! %s\n", strerror(errno));
}
void HCamDevice::HtCamExitVideoCapturing()
{
//HtCamStopVideoCapturing();
HtCamStopVideoCapturing();
uint8_t i;
for (i = 0; i < v4lBufferCount; ++i)
@ -257,10 +259,6 @@ void HCamDevice::HtCamExitVideoCapturing()
if (-1 == munmap(captureBufers[i].start, captureBufers[i].length))
printf("munmap \n");
}
if(close(videofd)<0)
{
camera_err("close video fd error \n");
}
if(close(memfd)<0)
{
camera_err("close mem fd error \n");
@ -308,20 +306,21 @@ int HCamDevice::read_frame(void **pbuf, int timeout)
buf.length = nplanes;
buf.m.planes = (struct v4l2_plane *)calloc(nplanes, sizeof(struct v4l2_plane));
}
int ret = ioctl(videofd, VIDIOC_DQBUF, &buf);
if ( ret == 0)
camera_dbg("*****DQBUF[%d] FINISH*****\n", buf.index);
else
{
camera_err("****DQBUF FAIL %d*****\n",ret);
//return -2;
return -2;
}
if (ioctl(videofd, VIDIOC_QBUF, &buf) == 0)
camera_dbg("************QBUF[%d] FINISH buffer size:%d**************\n", buf.index,buf.length);
else
{
//return -2;
return -2;
}
lastSucceedBufferIndex = buf.index;
*pbuf = captureBufers[buf.index].start;
@ -385,9 +384,20 @@ int HCamDevice::HtCamStopSampling()
printf("设置停止采图寄存器\r\n");
CamReg = (uint32_t *)virBaseAddr;
//CamReg[10] |= (HT_CAM_REG_CR_STARTSAMPLE_MASK);
// CamReg[10] &= ~ (HT_CAM_REG_CR_STOPSAMPLE_MASK);
// CamReg[10] |= (HT_CAM_REG_CR_STOPSAMPLE_MASK); //1
// CamReg[10] |= (HT_CAM_REG_CR_STOPSAMPLE_MASK);
// CamReg[10] &= ~(HT_CAM_REG_CR_STOPSAMPLE_MASK); //0
// CamReg[10] |= (HT_CAM_REG_CR_STARTSAMPLE_MASK);
// CamReg[10] &= ~(HT_CAM_REG_CR_STARTSAMPLE_MASK); //0
CamReg[10] |= (HT_CAM_REG_CR_STOPSAMPLE_MASK);
CamReg[10] &= ~(HT_CAM_REG_CR_STOPSAMPLE_MASK);
return 0;
}

View File

@ -1,43 +1,43 @@
// #include "Jpegcompress.h"
// #include <string>
#include "Jpegcompress.h"
#include <string>
// JpegCompress::JpegCompress(int quality):tjInstance(NULL)
// ,m_quality(quality)
// {
// }
JpegCompress::JpegCompress(int quality):tjInstance(NULL)
,m_quality(quality)
{
}
// JpegCompress::~JpegCompress()
// {
// tjDestroy(tjInstance);
// }
JpegCompress::~JpegCompress()
{
tjDestroy(tjInstance);
}
// HG_JpegCompressInfo JpegCompress::GetCompressedImg(cv::Mat& mat)
// {
// HG_JpegCompressInfo info={0};
// if(mat.empty())
// {
// LOG("JpegCompress Empty Mat! warnning !!!!\n");
// return info;
// }
// tjInstance = tjInitCompress();
// int outSubsamp;
// int flags = 0;
// int pixelFormat;
// if (mat.channels() == 1)
// {
// outSubsamp = TJSAMP_GRAY;
// pixelFormat = TJPF_GRAY;
// }
// else
// {
// pixelFormat = TJPF_RGB;
// outSubsamp = TJSAMP_444;
// }
// //std::chrono::steady_clock::time_point _start = std::chrono::steady_clock::now();
// //LOG("image rows= %d cols= %d pixelFormat= %d \n",mat.rows,mat.cols,pixelFormat);
// tjCompress2(tjInstance, mat.data, mat.cols, 0, mat.rows, pixelFormat,
// &info.pJpegData, (long unsigned int*)&info.DataLength, outSubsamp, m_quality, flags);
HG_JpegCompressInfo JpegCompress::GetCompressedImg(cv::Mat& mat)
{
HG_JpegCompressInfo info={0};
if(mat.empty())
{
LOG("JpegCompress Empty Mat! warnning !!!!\n");
return info;
}
tjInstance = tjInitCompress();
int outSubsamp;
int flags = 0;
int pixelFormat;
if (mat.channels() == 1)
{
outSubsamp = TJSAMP_GRAY;
pixelFormat = TJPF_GRAY;
}
else
{
pixelFormat = TJPF_RGB;
outSubsamp = TJSAMP_444;
}
//std::chrono::steady_clock::time_point _start = std::chrono::steady_clock::now();
LOG("image rows= %d cols= %d pixelFormat= %d \n",mat.rows,mat.cols,pixelFormat);
tjCompress2(tjInstance, mat.data, mat.cols, 0, mat.rows, pixelFormat,
&info.pJpegData, (long unsigned int*)&info.DataLength, outSubsamp, m_quality, flags);
// //LOG("jpeg compress done \n");
// return info;
// }
//LOG("jpeg compress done \n");
return info;
}

View File

@ -1,15 +1,15 @@
// #pragma once
// #include <turbojpeg.h>
// #include <opencv2/opencv.hpp>
// #include "scanservices_utils.h"
#pragma once
#include <turbojpeg.h>
#include <opencv2/opencv.hpp>
#include "scanservices_utils.h"
// class JpegCompress
// {
// public:
// JpegCompress(int quality=80);
// ~JpegCompress();
// HG_JpegCompressInfo GetCompressedImg(cv::Mat& mat);
// private:
// tjhandle tjInstance;
// int m_quality;
// };
class JpegCompress
{
public:
JpegCompress(int quality=80);
~JpegCompress();
HG_JpegCompressInfo GetCompressedImg(cv::Mat& mat);
private:
tjhandle tjInstance;
int m_quality;
};

View File

@ -1,6 +1,6 @@
#include "MultiFrameCapture.h"
#include <thread>
// #include <opencv2/opencv.hpp>
#include <opencv2/opencv.hpp>
#include "DevUtil.h"
#include "Gpio.h"
#include "FpgaComm.h"
@ -93,7 +93,7 @@ void MultiFrameCapture::open()
{
// reset_fpga();
m_capFpageregs->resetADC();
m_capFpageregs->set_cis_type(false); // 适配A4 CIS
//m_capFpageregs->set_cis_type(false); // 适配A4 CIS
const bool dunnancis = true;
is_size_error = false;
// m_frames.clear();
@ -129,7 +129,7 @@ void MultiFrameCapture::open()
if ((m_config.params.pageSize == 17 || m_config.params.pageSize == 19) && m_config.params.dpi == 3)
pixheight /= 2;
// pixheight = 8100;
printf("########## pixheight = %d phyHeight = %d m_config.params.pageSize %d dpi = %d\n", pixheight, phyHeight, m_config.params.pageSize, dpi);
frame_height = 300 * channels;
// frame_height = (dpi > 2 ? 300 : 180) * channels;
@ -137,7 +137,7 @@ void MultiFrameCapture::open()
frame_count += 1; // 最后一帧丢帧,多采集一帧防止图像数据缺失
if (frame_height * frame_count > FPGA_MAX_HEIGHT_SUP)
frame_count = FPGA_MAX_HEIGHT_SUP / frame_height;
printf("########## pixheight = %d phyHeight = %d m_config.params.pageSize %d dpi = %d frame_count=%d\n", pixheight, phyHeight, m_config.params.pageSize, dpi,frame_count);
int startsample = 202; // 205
ModeFpga fpgamod = {
.colorMode = mode,
@ -201,8 +201,9 @@ void MultiFrameCapture::snap()
{
#ifndef TEST_SIMCAP
std::lock_guard<std::mutex> m_lock(m_mtx_snap);
b_stop_snap = b_end_snap = false;
m_capFpageregs->capture();
b_stop_snap = b_end_snap = false;
stop_snap =true;
//m_capFpageregs->capture();
video->HtCamStartSampling();
snaped_index++;
m_cv_snap.notify_all();
@ -215,6 +216,8 @@ void MultiFrameCapture::stopsnap(bool autosize)
{
b_stop_snap = true;
}
//b_stop_snap =false;
stop_snap =false;
video->HtCamStopSampling();
}
@ -530,23 +533,44 @@ int MultiFrameCapture::color()
return m_capFpageregs->getColorMode();
}
// int MultiFrameCapture::imageProcessCurrentFrame()
// {
// }
static int cnt = 0;
void MultiFrameCapture::snaprun()
{
auto snap_func = [this](V4L2_DATAINFO_Ex frame_info, int channels, bool last_frame, unsigned int frame_index)
{
// void *data = video->read_frame(500);
char *data = NULL;
video->read_frame((void **)&data, 400);
frame_info.lost_frame = data ? false : true;
frame_info.last_frame = last_frame;
unsigned char *data = NULL;
video->read_frame((void **)&data, 100);
// int width = 0;
// int height = 0;
// unsigned char* send_buf = imageProcessCurrentFrame(data , width, height);
// frame_info.lost_frame = data ? false : true;
// frame_info.last_frame = last_frame;
frame_info.frame_index = frame_index;
//frame_info.width = video->HtCamReadFpgaRegs(14);//15552/3;
//frame_info.height = 128;
printf("+++++++++++++++ image pdata =%p frame_info.width :%d\n",data,frame_info.width);
if (data)
{
// cv::Mat mat(frame_info.height, frame_info.width, CV_8UC1, data);
frame_info.data = (char *)data;
//cv::Mat mat(frame_info.height, frame_info.width, CV_8UC1, data);
cv::Mat mat = cv::Mat(frame_info.height, frame_info.width, CV_8UC1, data, cv::Mat::AUTO_STEP);
frame_info.width = mat.cols;
frame_info.height = mat.rows;
//cv::imwrite("/home/root/test.png", mat);
frame_info.data = data;
m_frameinfos.Put(frame_info);
printf("获取数据\r\n");
printf("获取数据 width:%d height:%d\r\n",frame_info.width,frame_info.height);
}
else
{
@ -554,42 +578,79 @@ void MultiFrameCapture::snaprun()
printf("!!!!!!!!!! error read frame losted, i = %d \n", frame_index);
}
};
stop_snap =true;
while (b_snap_run)
{
std::unique_lock<std::mutex> lock(m_mtx_snap);
m_cv_snap.wait(lock);
V4L2_DATAINFO_Ex frame_info;
int channels = this->color() ? 3 : 1;
int width = this->width() * channels * 6;
frame_info.pixtype = this->color();
int width = 11016;//video->HtCamReadFpgaRegs(14);//this->width() * channels * 6;
printf("---------------------width------------------ :%d\r\n",width);
frame_info.pixtype = 0;//this->color();
frame_info.dpi = m_config.params.dpi;
frame_info.width = width;
frame_info.error_code = 0;
frame_info.height = frame_height / channels;
frame_info.height = 128;//frame_height / channels;
// 从mat信息中获取宽高信息
frame_info.snaped_index = snaped_index;
frame_info.first_frame = false;
frame_info.last_frame = false;
int trigger_mode = video->HtCamGetTriggerMode();
int color_mode = video->HtCamGetColorMode();
void *data;
for (int i = 1; i <= frame_count; i++)
int i = 0;
while (stop_snap)
{
snap_func(frame_info, channels, (i == frame_count), i);
if (b_stop_snap)
{
int snaped_frame_count = m_capFpageregs->getFrame_counter_val();
printf("!!!!!!!!!! revsed frame count = %d i = %d \n", snaped_frame_count, i);
if (snaped_frame_count > i && snaped_frame_count > 0) // 正常情况下 snaped_frame_count 一定大于0
{
int reversed_frame_count = snaped_frame_count - i;
for (int j = 1; j <= reversed_frame_count; j++)
{
snap_func(frame_info, channels, ((i + j) == reversed_frame_count), i + j);
}
}
break; // 跳出当前读取多帧循环
}
if (i == 0)
frame_info.first_frame = true;
else
frame_info.first_frame = false;
snap_func(frame_info, channels, false, i);
i++;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
// iImageremain++;
frame_info.last_frame = true; //当前最后一帧
snap_func(frame_info, channels, frame_info.last_frame, ++i);
printf("----------停止采集图像----------\r\n");
// if (stop_snap)
// {
// }
// else
// {
// printf("----------停止采集图像----------\r\n");
// snap_func(frame_info, channels, false, iImageremain);
// iImageremain++;
// break;
// }
// for (int i = 1; i <= 20; i++)
// {
// snap_func(frame_info, channels, (i == frame_count), i);
// if (b_stop_snap)
// {
// int snaped_frame_count = m_capFpageregs->getFrame_counter_val();
// printf("!!!!!!!!!! revsed frame count = %d i = %d \n", snaped_frame_count, i);
// if (snaped_frame_count > i && snaped_frame_count > 0) // 正常情况下 snaped_frame_count 一定大于0
// {
// int reversed_frame_count = snaped_frame_count - i;
// for (int j = 1; j <= reversed_frame_count; j++)
// {
// // snap_func(frame_info, channels, ((i + j) == reversed_frame_count), i + j);
// }
// }
// break; // 跳出当前读取多帧循环
// }
// }
iImageremain++;
m_cv_snapdone.notify_all();
b_end_snap = true;
// printf("!!!!!!!!!!!!!!!! m_cv_snapdone notify_all \n");
@ -606,142 +667,162 @@ void MultiFrameCapture::procimage()
{
static int idx = 0;
ThreadPool prc_pool(4);
// td::queue<std::future<cv::Mat>> prc_fu;
std::queue<std::future<cv::Mat>> prc_fu;
unsigned int frames_height;
unsigned int frames_width = 0;
while (b_imgproc)
{
V4L2_DATAINFO_Ex frame = m_frameinfos.Take();
if (!frame.data)
{
HG_JpegCompressInfo info;
info.pJpegData = (unsigned char *)frame.data;
info.DataLength = frame.width * frame.height;
static int inx = 0;
printf("++++++++++++++++++++++++++++++++++++++ image save\r\n");
if(!frame.data)
printf("++++++++++++++++++++++++++++++++++++++ frame.mat.empty()\r\n");
// else
// cv::imwrite(std::to_string(++inx)+".bmp",frame.mat);
if (frame.data)
{
//iImageremain--;
HG_JpegCompressInfo info;
info.pJpegData = frame.data;
info.DataLength = frame.width * frame.height;
info.first_frame = frame.first_frame;
info.last_frame = frame.last_frame;
info.index_frame = frame.frame_index;
m_glue.m_imageready(info);
printf("frame.snaped_index = %d \n frame.frame_index =%d \n frame.lost_frame = %d \n frame.last_frame = %d \n frame.pixtype = %d\n",
frame.snaped_index,
frame.frame_index,
frame.lost_frame,
frame.last_frame,
frame.pixtype
);
}
break;
// if (!frame.data)
continue;
// if (frame.data)
// {
// prc_fu.push(prc_pool.enqueue([this, &frames_height, &frames_width](V4L2_DATAINFO_Ex frame) -> cv::Mat
// {
// CImageMerge imgmerge;
// // cv::imwrite(std::to_string(++idx) +"index"+std::to_string(frame.snaped_index)+ "org.jpg", frame.mat);
// auto img = imgmerge.MergeImage(frame.mat, frame.width, frame.height, frame.pixtype);
// // cv::imwrite(std::to_string(++idx) + "mrg.jpg", img);
// //cv::imwrite(std::to_string(++idx) + "mrg.jpg", img);
// // printf(" img height = %d width = %d \n",img.rows,img.cols);
// printf(" img height = %d width = %d \n",img.rows,img.cols);
// if (m_config.params.pageSize == 17 || m_config.params.pageSize == 19)
// {
// if (m_config.params.isCorrect)
// correctColor(img, 2, m_config.params.isColor, false);
// if (m_config.params.dpi != 2)
// cv::resize(img, img, cv::Size(0, 0), m_config.params.dpi == 1 ? 1.0 : 2.0, m_config.params.dpi == 1 ? (2.0 / 3.0) : 2.0);
// if (m_config.params.isCorrect){
// myFloodFill(img,true);
// }
// // if (m_config.params.isCorrect)
// // correctColor(img, 2, m_config.params.isColor, false);
// // if (m_config.params.dpi != 2)
// // cv::resize(img, img, cv::Size(0, 0), m_config.params.dpi == 1 ? 1.0 : 2.0, m_config.params.dpi == 1 ? (2.0 / 3.0) : 2.0);
// // if (m_config.params.isCorrect){
// // myFloodFill(img,true);
// // }
// }
// else if (m_config.params.isCorrect)
// // else if (m_config.params.isCorrect)
// correctColor(img, m_config.params.dpi, m_config.params.isColor, false);
// // cv::imwrite(std::to_string(++idx) + "correct.jpg", img);
// // printf("frame.snaped_index = %d \n frame.frame_index =%d \n frame.lost_frame = %d \n frame.last_frame = %d \n frame.pixtype = %d\n",
// // frame.snaped_index,
// // frame.frame_index,
// // frame.lost_frame,
// // frame.last_frame,
// // frame.pixtype
// // );
// printf("frame.snaped_index = %d \n frame.frame_index =%d \n frame.lost_frame = %d \n frame.last_frame = %d \n frame.pixtype = %d\n",
// frame.snaped_index,
// frame.frame_index,
// frame.lost_frame,
// frame.last_frame,
// frame.pixtype
// );
// // m_frames.push_back(img);
// // frames_height += img.rows;
// // frames_width = img.cols;
// // printf("frames_height = %d frames_width = %d index = %d \n",frames_height,frames_width,idx++);
// // printf("call back frames_height = %d frames_width = %d index = %d \n",frames_height,frames_width,idx++);
// return img;
// // update_imgdatainfo(img);
// // img.release();
// },
// frame));
// }
// if (prc_fu.size() > 4)
// {
// auto img = prc_fu.front().get();
// frames_height += img.rows;
// frames_width = img.cols;
// update_imgdatainfo(img);
// prc_fu.pop();
// }
// if (frame.snap_end)
// {
// while (prc_fu.size())
// {
// auto img = prc_fu.front().get();
// frames_height += img.rows;
// frames_width = img.cols;
// update_imgdatainfo(img);
// prc_fu.pop();
// }
// if (frame.error_code)
// {
// iImageremain--;
// // m_frames.clear();
// //printf("!!!!!!!!!!!!!!!!!!!!!! frame.error_code = %d \n", frame.error_code);
// frames_height = frames_width = 0;
// reset_imagedata();
// continue;
// }
// // cv::Mat m_mat(frames_height,frames_width ,CV_8UC(m_config.params.isColor ?3:1));
// // unsigned int copy_height =0;
// // for(auto& mat : m_frames)
// // {
// // mat.copyTo(m_mat(cv::Rect(0,copy_height,mat.cols,mat.rows)));
// // copy_height+=mat.rows;
// // }
if (prc_fu.size() > 4)
{
auto img = prc_fu.front().get();
frames_height += img.rows;
frames_width = img.cols;
update_imgdatainfo(img);
prc_fu.pop();
}
if (frame.snap_end)
{
printf("111111111111111111111111111111111111111111111\r\n");
while (prc_fu.size())
{
auto img = prc_fu.front().get();
frames_height += img.rows;
frames_width = img.cols;
update_imgdatainfo(img);
prc_fu.pop();
}
if (frame.error_code)
{
iImageremain--;
// m_frames.clear();
printf("!!!!!!!!!!!!!!!!!!!!!! frame.error_code = %d \n", frame.error_code);
frames_height = frames_width = 0;
reset_imagedata();
continue;
}
// cv::Mat m_mat(frames_height,frames_width ,CV_8UC(m_config.params.isColor ?3:1));
// unsigned int copy_height =0;
// for(auto& mat : m_frames)
// {
// mat.copyTo(m_mat(cv::Rect(0,copy_height,mat.cols,mat.rows)));
// copy_height+=mat.rows;
// }
// // m_frames.clear();
// //printf("frames_height = %d frames_width = %d pimgdata_info = %d\n", frames_height, frames_width, pimgdata_info.total_dst);
// cv::Mat m_mat;
// if (frames_height > 0 && frames_width > 0)
// m_mat = cv::Mat(frames_height, frames_width, CV_8UC(m_config.params.isColor ? 3 : 1), pimgdata_info.pdata);
// m_frames.clear();
printf("frames_height = %d frames_width = %d pimgdata_info = %d\n", frames_height, frames_width, pimgdata_info.total_dst);
cv::Mat m_mat;
if (frames_height > 0 && frames_width > 0)
m_mat = cv::Mat(frames_height, frames_width, CV_8UC(m_config.params.isColor ? 3 : 1), pimgdata_info.pdata);
//m_mat = cv::Mat(frames_height, frames_width, CV_8UC(m_config.params.isColor ? 3 : 1), pimgdata_info.pdata);
// float vratio = *((float *)&m_fpgaparam.VRatio);
// float hratio = *((float *)&m_fpgaparam.HRatio);
// if (!(vratio >= 0.8f && vratio <= 1.20f && hratio > 0.8f && hratio < 1.2f))
// vratio = hratio = 1.0f;
// if (m_config.params.dpi == 1)
// hratio = (200.0 / 300.0) * hratio;
float vratio = *((float *)&m_fpgaparam.VRatio);
float hratio = *((float *)&m_fpgaparam.HRatio);
if (!(vratio >= 0.8f && vratio <= 1.20f && hratio > 0.8f && hratio < 1.2f))
vratio = hratio = 1.0f;
if (m_config.params.dpi == 1)
hratio = (200.0 / 300.0) * hratio;
// if (!m_mat.empty())
// {
// resize(m_mat, m_mat, cv::Size(0, 0), hratio, vratio);
// // printf("!!!!!!!!!!!!!!!!!!!!!! hratio = %f vratio = %f snapindex = %d \n",hratio,vratio,frame.snaped_index);
// for (int i = 0; i < m_preproclist.size(); i++)
// {
// LOG("error m_preproclist \n");
// auto halfimg = m_mat(cv::Rect(0, 0, m_mat.cols / 2, m_mat.rows));
// int ret = m_preproclist[i]->preprocess(halfimg, nullptr);
// if (ret)
// {
// m_glue.m_deviceevent((int)HG_ScannerStatus::SIZE_ERROR, "size error");
// is_size_error = true;
// }
// }
// frames_height = frames_width = 0;
// auto dst_a = m_mat(cv::Rect(0, 0, m_mat.cols / 2, m_mat.rows));
// auto dst_b = m_mat(cv::Rect(m_mat.cols / 2, 0, m_mat.cols / 2, m_mat.rows));
// cv::flip(m_mat(cv::Rect(0, 0, m_mat.cols / 2, m_mat.rows)), dst_a, 1);
// cv::flip(m_mat(cv::Rect(m_mat.cols / 2, 0, m_mat.cols / 2, m_mat.rows)), dst_b, 1);
// // printf("!!!!!!!!!!!!!!!!!!!!!! frames height = %d m_mat height = %d\n",copy_height,m_mat.rows);
// }
if (!m_mat.empty())
{
resize(m_mat, m_mat, cv::Size(0, 0), hratio, vratio);
// printf("!!!!!!!!!!!!!!!!!!!!!! hratio = %f vratio = %f snapindex = %d \n",hratio,vratio,frame.snaped_index);
for (int i = 0; i < m_preproclist.size(); i++)
{
// LOG("error m_preproclist \n");
// auto halfimg = m_mat(cv::Rect(0, 0, m_mat.cols / 2, m_mat.rows));
// int ret = m_preproclist[i]->preprocess(halfimg, nullptr);
// if (ret)
// {
// m_glue.m_deviceevent((int)HG_ScannerStatus::SIZE_ERROR, "size error");
// is_size_error = true;
// }
}
frames_height = frames_width = 0;
auto dst_a = m_mat(cv::Rect(0, 0, m_mat.cols / 2, m_mat.rows));
auto dst_b = m_mat(cv::Rect(m_mat.cols / 2, 0, m_mat.cols / 2, m_mat.rows));
cv::flip(m_mat(cv::Rect(0, 0, m_mat.cols / 2, m_mat.rows)), dst_a, 1);
cv::flip(m_mat(cv::Rect(m_mat.cols / 2, 0, m_mat.cols / 2, m_mat.rows)), dst_b, 1);
// printf("!!!!!!!!!!!!!!!!!!!!!! frames height = %d m_mat height = %d\n",copy_height,m_mat.rows);
}
// JpegCompress cmp(90);
// HG_JpegCompressInfo info = cmp.GetCompressedImg(m_mat);
// if (info.pJpegData != nullptr && info.DataLength != 0 && !is_size_error)
// {
// m_glue.m_imageready(info);
// }
// iImageremain--;
// reset_imagedata();
// }
JpegCompress cmp(90);
HG_JpegCompressInfo info = cmp.GetCompressedImg(m_mat);
if (info.pJpegData != nullptr && info.DataLength != 0 && !is_size_error)
{
m_glue.m_imageready(info);
}
iImageremain--;
reset_imagedata();
}
}
}
@ -1297,19 +1378,19 @@ void MultiFrameCapture::init_imagedatabuffer()
#endif
}
// void MultiFrameCapture::update_imgdatainfo(cv::Mat itemmat)
// {
// if (pimgdata_info.pdata)
// {
// if (!itemmat.empty())
// {
// // printf("pimgdata_info.pdata = %p offset = %d item_total = %d \n", pimgdata_info.pdata, pimgdata_info.offset, itemmat.total()*itemmat.elemSize());
// memcpy(pimgdata_info.pdata + pimgdata_info.offset, (void *)itemmat.data, itemmat.total() * itemmat.elemSize());
// pimgdata_info.offset += itemmat.total() * itemmat.elemSize();
// pimgdata_info.frame_count++;
// }
// }
// }
void MultiFrameCapture::update_imgdatainfo(cv::Mat itemmat)
{
if (pimgdata_info.pdata)
{
if (!itemmat.empty())
{
printf("pimgdata_info.pdata = %p offset = %d item_total = %d \n", pimgdata_info.pdata, pimgdata_info.offset, itemmat.total()*itemmat.elemSize());
memcpy(pimgdata_info.pdata + pimgdata_info.offset, (void *)itemmat.data, itemmat.total() * itemmat.elemSize());
pimgdata_info.offset += itemmat.total() * itemmat.elemSize();
pimgdata_info.frame_count++;
}
}
}
void MultiFrameCapture::reset_imagedata()
{
if (pimgdata_info.pdata)

View File

@ -32,6 +32,7 @@ private:
BlockingQueue<V4L2_DATAINFO_Ex> m_frameinfos;
bool b_snap_run;
bool b_stop_snap;
bool stop_snap = false ;
bool b_end_snap;
bool b_imgproc;
bool is_size_error;
@ -77,7 +78,7 @@ private:
void openDevice(int dpi,int mode);
//void myFloodFill(cv::Mat& image, bool isTwoSide);
void init_imagedatabuffer();
//void update_imgdatainfo(cv::Mat itemmat);
void update_imgdatainfo(cv::Mat itemmat);
void reset_imagedata();
public:

View File

@ -366,8 +366,10 @@ void Scanner::runScan()
if(sensor->isPaperAtScan())
{
m_glue.m_deviceevent((int)HG_ScannerStatus::PAPER_HOLE,"paper have hole");
capturer->stopsnap(b_autosize);
capturer->waitsnapdone(1);//等待采集完成
capturer->stopsnap(b_autosize);
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
@ -380,7 +382,6 @@ void Scanner::runScan()
m_scaninfo.TotalScanned++;
tmp_recordScannum++;
writesyslog(LOG_INFO, getmeminfo());
if (m_DstScannum == 0)
{
LOG("\n ----------------EXIT 2222 cnt=%d---------------- \n",m_DstScannum);

View File

@ -5,7 +5,7 @@
#include "correct_ultis.h"
#include "CImageMerge.h"
#define USE_NEWFLAT
//using namespace cv;
using namespace cv;
//设置一面的offset值
void setOffset(int *config, int step)
@ -33,94 +33,94 @@ void setOffset(int *config, int step)
// return BWbalenceSrc;
// }
// cv::Mat loadLUT(const std::string &file)
// {
// cv::Mat dataFile = cv::imread(file, cv::IMREAD_ANYCOLOR);
// long total = dataFile.total();
// int step = total / 256;
cv::Mat loadLUT(const std::string &file)
{
cv::Mat dataFile = cv::imread(file, cv::IMREAD_ANYCOLOR);
long total = dataFile.total();
int step = total / 256;
// int channel = 1;
// #ifndef USE_NEWFLAT
// if (step == 4896 || step == 7344)
// channel = 408;
// else if (step == 14688 || step == 22032 || step == 44064)
// channel = 432; // 486
// #else
// #ifdef G400
// channel = 408;
// #else
// channel = 432;
// #endif
// #endif
// cv::Mat lut(step / channel, 256, CV_8UC(channel));
// memcpy(lut.data, dataFile.data, total);
// return lut;
// }
int channel = 1;
#ifndef USE_NEWFLAT
if (step == 4896 || step == 7344)
channel = 408;
else if (step == 14688 || step == 22032 || step == 44064)
channel = 432; // 486
#else
#ifdef G400
channel = 408;
#else
channel = 432;
#endif
#endif
cv::Mat lut(step / channel, 256, CV_8UC(channel));
memcpy(lut.data, dataFile.data, total);
return lut;
}
void initLut(const std::string lutpath, bool iscolor)
{
// if (!lutpath.empty() && (access(lutpath.c_str(), F_OK) == 0))
// {
// if (iscolor)
// {
// lutColorMat = loadLUT(lutpath); //彩色校正值
// }
// else
// lutGrayMat = loadLUT(lutpath); //灰色校正值
// }
if (!lutpath.empty() && (access(lutpath.c_str(), F_OK) == 0))
{
if (iscolor)
{
lutColorMat = loadLUT(lutpath); //彩色校正值
}
else
lutGrayMat = loadLUT(lutpath); //灰色校正值
}
}
// void correctColor(cv::Mat &src, int dpi, int mode, bool lutgraghic)
// {
// Mat lutMat;
// #ifdef USE_NEWFLAT
// FPGAConfigParam param = GetFpgaparam(dpi, mode);
// std::string path = lutgraghic ? param.LutPath : param.TextLutPath;
// #else
// std::string path = param.LutPath;
// #endif
// if (src.type() == CV_8UC3)
// {
// if (lutColorMat.empty())
// {
// if (access(path.c_str(), F_OK) != -1)
// {
// lutColorMat = loadLUT(path);
// }
// else
// {
// printf("error error error %s NOT FOUND \n", path.c_str());
// return;
// }
// }
// lutMat = lutColorMat;
// }
// else
// {
// if (lutGrayMat.empty())
// {
// if (access(path.c_str(), F_OK) != -1)
// {
// lutGrayMat = loadLUT(path);
// }
// else
// {
// printf("error error error %s NOT FOUND", path.c_str());
// return;
// }
// }
// lutMat = lutGrayMat;
// }
// if (lutMat.empty())
// {
// return;
// }
void correctColor(cv::Mat &src, int dpi, int mode, bool lutgraghic)
{
cv::Mat lutMat;
#ifdef USE_NEWFLAT
FPGAConfigParam param = GetFpgaparam(dpi, mode);
std::string path = lutgraghic ? param.LutPath : param.TextLutPath;
#else
std::string path = param.LutPath;
#endif
if (src.type() == CV_8UC3)
{
if (lutColorMat.empty())
{
if (access(path.c_str(), F_OK) != -1)
{
lutColorMat = loadLUT(path);
}
else
{
printf("error error error %s NOT FOUND \n", path.c_str());
return;
}
}
lutMat = lutColorMat;
}
else
{
if (lutGrayMat.empty())
{
if (access(path.c_str(), F_OK) != -1)
{
lutGrayMat = loadLUT(path);
}
else
{
printf("error error error %s NOT FOUND", path.c_str());
return;
}
}
lutMat = lutGrayMat;
}
if (lutMat.empty())
{
return;
}
// cv::Mat image_temp(src.rows, src.cols * src.channels() / lutMat.channels(), CV_8UC(lutMat.channels()), src.data);
cv::Mat image_temp(src.rows, src.cols * src.channels() / lutMat.channels(), CV_8UC(lutMat.channels()), src.data);
// for (size_t i = 0; i < image_temp.cols; i++)
// cv::LUT(image_temp(cv::Rect(i, 0, 1, image_temp.rows)), lutMat(cv::Rect(0, i, 256, 1)), image_temp(cv::Rect(i, 0, 1, image_temp.rows)));
// }
for (size_t i = 0; i < image_temp.cols; i++)
cv::LUT(image_temp(cv::Rect(i, 0, 1, image_temp.rows)), lutMat(cv::Rect(0, i, 256, 1)), image_temp(cv::Rect(i, 0, 1, image_temp.rows)));
}
// void creatLUTData(int dpi, int mode)
// {

View File

@ -1,13 +1,13 @@
#pragma once
#include <sstream>
//#include <opencv2/opencv.hpp>
#include <opencv2/opencv.hpp>
#include "CameraParam.h"
#include "CorrectParam.h"
#include "CImageMerge.h"
//static cv::Mat lutGrayMat; //灰色校正值
//static cv::Mat lutColorMat; //彩色校正值
static cv::Mat lutGrayMat; //灰色校正值
static cv::Mat lutColorMat; //彩色校正值
static CorrectParam correctparam;
void initStep();
@ -20,7 +20,7 @@ void setOffset(int *config, int step);
void initLut(const std::string lutpath,bool iscolor);
//void correctColor(cv::Mat& src, int dpi,int mode,bool isTextCorrect=true);
void correctColor(cv::Mat& src, int dpi,int mode,bool isTextCorrect=true);
void creatLUTData(int dpi , int mode);

View File

@ -2,7 +2,7 @@
#include <string>
#include <functional>
#include <map>
//#include <opencv2/opencv.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
@ -84,6 +84,9 @@ struct HG_JpegCompressInfo
{
unsigned char *pJpegData;
unsigned int DataLength;
bool first_frame;
bool last_frame;
bool index_frame;
};
@ -272,7 +275,7 @@ struct ScannerGlue
struct V4L2_DATAINFO
{
//cv::Mat mat;
char *data;
unsigned char *data;
int width;
int height;
int pixtype;
@ -284,6 +287,7 @@ struct V4L2_DATAINFO_Ex:V4L2_DATAINFO
unsigned int frame_index;
unsigned int dpi;
unsigned int error_code;
bool first_frame;
bool lost_frame;
bool last_frame;
bool snap_end;

View File

@ -379,15 +379,15 @@ void stop_countdown()
void init_get_CISType_GPIO()
{
system("echo 190 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio190/direction");
system("echo 191 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio191/direction");
// system("echo 190 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio190/direction");
// system("echo 191 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio191/direction");
system("echo 233 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio233/direction");
system("echo 234 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio234/direction");
// system("echo 233 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio233/direction");
// system("echo 234 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio234/direction");
}
CISVendor GetCisType()