rk3399_arm_lvds/scanner/imagesavehandler.cpp

62 lines
1.7 KiB
C++
Raw Permalink Normal View History

2024-03-05 03:46:18 +00:00
#include "imagesavehandler.h"
#include "imgproc.h"
#include "opencv2/opencv.hpp"
#include "stringex.hpp"
#include <iostream>
ImageSaveHandler::ImageSaveHandler()
: pool(4)
{
}
ImageSaveHandler::~ImageSaveHandler()
{
}
void ImageSaveHandler::add_image(void *data, int width, int height, int type, int scannnum,unsigned int fpgaversion)
{
static int indexx = 0;
std::string path = std::to_string(++indexx) + ".png";
results.emplace_back(
pool.enqueue([data, width, height, type, path] {
cv::Mat mat;
cv::Mat saveMat;
std::vector<cv::Mat> ch_mats;
int dstwidth, dstheight;
dstwidth = width * 3;
dstheight = height / 3;
std::cout << path << std::endl;
if (type == CV_8UC3)
{
mat = cv::Mat(height / 3, width * 9, CV_8UC1, data);
saveMat = cv::Mat(dstheight, dstwidth, CV_8UC3);
}
else
{ //gray
saveMat = cv::Mat(height / 3, width * 3, CV_8UC1, data);
}
static int savenum;
if (type == CV_8UC3)
{
for (int i = 0; i < 3; i++)
{ // B G R
cv::Mat mattemp = mat(cv::Rect(dstwidth * i, 0, dstwidth, dstheight));
ch_mats.push_back(mattemp);
}
swap(ch_mats[1], ch_mats[2]);
cv::merge(ch_mats, saveMat);
}
std::cout << string_format("wdith:%d, height:%d\n", saveMat.cols, saveMat.rows) << std::endl;
cv::imwrite(path, saveMat);
return 0;
}));
}
bool ImageSaveHandler::done()
{
return true;
}