133 lines
5.9 KiB
C
133 lines
5.9 KiB
C
|
#pragma once
|
||
|
#include "iimagehandler.h"
|
||
|
#include "ThreadPool.h"
|
||
|
#include "imemory.h"
|
||
|
#include <queue>
|
||
|
#include <string>
|
||
|
#include <mutex>
|
||
|
#include "BlockingQueue.h"
|
||
|
|
||
|
|
||
|
class UsbImageProcQueue;
|
||
|
class HG_RGA_;
|
||
|
|
||
|
class ImageUsbHandler: public IImageHandler
|
||
|
{
|
||
|
public:
|
||
|
ImageUsbHandler(std::shared_ptr<UsbImageProcQueue> images = nullptr);
|
||
|
virtual ~ImageUsbHandler();
|
||
|
virtual void config_procparams(HGImgProcParms params);
|
||
|
virtual void add_image(void* data, int width, int height, int type,int scannnum,unsigned int fpgaversion = 0x90001,bool slow_moire = false,uint32_t error_code = 0) override;
|
||
|
virtual void add_image(void* data, int width, int height, int type,int scannnum,int frame_data_type,uint32_t adc_type,unsigned int fpgaversion = 0x90001,bool slow_moire = false,std::uint32_t error_code = 0) override;
|
||
|
virtual frame_data_info init_frame_data_info(cv::Size size);
|
||
|
virtual frame_data_info init_frame_data_info(uint32_t size);
|
||
|
virtual void free_frame_data(int type);
|
||
|
virtual void add_scanevent(HGIntInfo status);
|
||
|
virtual bool done();
|
||
|
virtual void clear();
|
||
|
virtual bool is_limit(uint32_t type) override;
|
||
|
virtual void Set_ratio(u32 h_ratio,u32 v_ratio) override;
|
||
|
|
||
|
private:
|
||
|
Error_Status Image_Detection(cv::Mat src,int type,bool slow_moire,int fpgaversion,int scannum);
|
||
|
void myFloodFill(cv::Mat &image, bool isTwoSide);
|
||
|
cv::Mat merge_color_8458(cv::Mat src)
|
||
|
{
|
||
|
cv::Mat dst(src.rows,src.cols/3,CV_8UC3);
|
||
|
int channle_w = src.cols / 12;
|
||
|
std::vector<cv::Mat> v_rgb;
|
||
|
for(int i = 0;i<3;i++)
|
||
|
{
|
||
|
cv::Mat tmp(src.rows,src.cols/3,CV_8UC1);
|
||
|
src(cv::Rect(channle_w*(0+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*1,0,channle_w,src.rows)));
|
||
|
src(cv::Rect(channle_w*(3+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*0,0,channle_w,src.rows)));
|
||
|
src(cv::Rect(channle_w*(6+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*3,0,channle_w,src.rows)));
|
||
|
src(cv::Rect(channle_w*(9+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*2,0,channle_w,src.rows)));
|
||
|
|
||
|
// src(cv::Rect(channle_w*(0+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*2,0,channle_w,src.rows)));
|
||
|
// src(cv::Rect(channle_w*(3+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*3,0,channle_w,src.rows)));
|
||
|
// src(cv::Rect(channle_w*(6+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*0,0,channle_w,src.rows)));
|
||
|
// src(cv::Rect(channle_w*(9+i),0,channle_w,src.rows)).copyTo(tmp(cv::Rect(channle_w*1,0,channle_w,src.rows)));
|
||
|
|
||
|
v_rgb.push_back(tmp);
|
||
|
}
|
||
|
cv::merge(v_rgb,dst);
|
||
|
return dst;
|
||
|
}
|
||
|
cv::Mat merge_8478(cv::Mat src, bool color, uint32_t version)
|
||
|
{
|
||
|
if(!color)
|
||
|
return src;
|
||
|
cv::Mat dst(src.rows, src.cols / 3, CV_8UC3);
|
||
|
cv::insertChannel(src(cv::Rect(0, 0, src.cols / 6, src.rows)), dst(cv::Rect(0,0,dst.cols/2,dst.rows)), 0);
|
||
|
cv::insertChannel(src(cv::Rect(src.cols / 3, 0, src.cols / 6, src.rows)), dst(cv::Rect(0, 0, dst.cols / 2, dst.rows)), 2);
|
||
|
cv::insertChannel(src(cv::Rect(src.cols / 3 * 2, 0, src.cols / 6, src.rows)), dst(cv::Rect(0, 0, dst.cols / 2, dst.rows)), 1);
|
||
|
cv::insertChannel(src(cv::Rect(src.cols / 6, 0, src.cols / 6, src.rows)), dst(cv::Rect(dst.cols / 2, 0, dst.cols / 2, dst.rows)), 0);
|
||
|
cv::insertChannel(src(cv::Rect(src.cols / 6 * 3, 0, src.cols / 6, src.rows)), dst(cv::Rect(dst.cols / 2, 0, dst.cols / 2, dst.rows)), 2);
|
||
|
cv::insertChannel(src(cv::Rect(src.cols / 6 * 5, 0, src.cols / 6, src.rows)), dst(cv::Rect(dst.cols / 2, 0, dst.cols / 2, dst.rows)), 1);
|
||
|
return dst;
|
||
|
}
|
||
|
|
||
|
|
||
|
cv::Mat interpolation_600dpi(cv::Mat src,bool side)
|
||
|
{
|
||
|
cv::Mat dst(src.rows, src.cols + (side + 1) * 16, CV_8UC(src.channels()));
|
||
|
int channel_w = side ? (src.cols / 17) : (src.cols / 17);
|
||
|
|
||
|
int copy_lenght = 0;
|
||
|
int dst_copy_lenght = 0;
|
||
|
std::vector<std::pair<int, int>> v;
|
||
|
for (int i = 0; i < ((side + 1) * 17); i++)
|
||
|
{
|
||
|
src(cv::Rect(copy_lenght, 0, channel_w, src.rows)).copyTo(dst(cv::Rect(dst_copy_lenght, 0, channel_w, src.rows)));
|
||
|
copy_lenght += channel_w;
|
||
|
dst_copy_lenght += channel_w + (i == 16 ? 0 : 1);
|
||
|
if (i == (side ? 33 : 16)) continue;
|
||
|
v.push_back({ copy_lenght ,dst_copy_lenght });
|
||
|
|
||
|
}
|
||
|
for (auto node : v)
|
||
|
{
|
||
|
if(src.channels() == 3){
|
||
|
cv::Vec3b f, b;
|
||
|
for (int row = 0; row < src.rows; row++)
|
||
|
{
|
||
|
f = src.at<cv::Vec3b>(row, node.first - 1);
|
||
|
b = src.at<cv::Vec3b>(row, node.first);
|
||
|
dst.at<cv::Vec3b>(row, node.second - 1)[0] = (f[0] + b[0]) / 2;
|
||
|
dst.at<cv::Vec3b>(row, node.second - 1)[1] = (f[1] + b[1]) / 2;
|
||
|
dst.at<cv::Vec3b>(row, node.second - 1)[2] = (f[2] + b[2]) / 2;
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
std::uint8_t f, b;
|
||
|
for (int row = 0; row < src.rows; row++)
|
||
|
{
|
||
|
f = src.at<std::uint8_t>(row, node.first - 1);
|
||
|
b = src.at<std::uint8_t>(row, node.first);
|
||
|
dst.at<std::uint8_t>(row, node.second - 1) = (f + b) / 2;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return dst;
|
||
|
}
|
||
|
|
||
|
protected:
|
||
|
|
||
|
std::shared_ptr<UsbImageProcQueue> images;
|
||
|
BlockingQueue<cv::Mat> capture_data;
|
||
|
BlockingQueue<cv::Mat> encode_data;
|
||
|
ThreadPool pool;
|
||
|
ThreadPool encodepools;
|
||
|
ThreadPool pushpool;
|
||
|
volatile float H_ratio;
|
||
|
volatile float V_ratio;
|
||
|
std::queue<std::future<void>> results;
|
||
|
std::queue<std::future<std::vector<MemoryPtr>>> encodeimgs;
|
||
|
BlockingQueue<SCAN_STATUS> scanEvents;
|
||
|
std::shared_ptr<std::uint8_t> m_frame_buf;
|
||
|
std::mutex mtx;
|
||
|
HGImgProcParms m_procparams;
|
||
|
std::unique_ptr<HG_RGA_> m_rga;
|
||
|
};
|