调整整体出图流程

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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