From cdc979ea38e76f36a70dd50e98813d8e73605f16 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Sat, 1 Jul 2023 19:04:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8E=E7=BC=80=E5=AF=BC=E8=87=B4cv::im=5Fwrite=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/image_process.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/hgdriver/hgdev/image_process.cpp b/hgdriver/hgdev/image_process.cpp index 7674098..67df4d3 100644 --- a/hgdriver/hgdev/image_process.cpp +++ b/hgdriver/hgdev/image_process.cpp @@ -225,7 +225,7 @@ namespace hg_imgproc ,Dynamicopen_HGBase_pHandle_(NULL) ,Dynamicopen_HGImageprc_pHandle_(NULL),isx86_Advan_(isx86_Advan) { - cv::setUseOptimized(isx86_Advan_); //开关cpu高级指令集 + cv::setUseOptimized(isx86_Advan_); //开关cpu高级指令? } ~imgproc() { @@ -326,7 +326,7 @@ namespace hg_imgproc { return SCANNER_ERR_OUT_OF_RANGE; } - printf("HGBaselib_path:%s HGImagePrclib_path:%s\r\n",HGBaselib_path.c_str(),HGImagePrclib_path.c_str()); + printf("HGBaselib_path?s HGImagePrclib_path:%s\r\n",HGBaselib_path.c_str(),HGImagePrclib_path.c_str()); Dynamicopen_HGImageprc_pHandle_ = dlopen(HGImagePrclib_path.c_str(), RTLD_LAZY); Dynamicopen_HGBase_pHandle_ = dlopen(HGBaselib_path.c_str(), RTLD_LAZY); @@ -511,7 +511,7 @@ namespace hg_imgproc catch (const std::exception& e) { LOG_INFO(LOG_LEVEL_FATAL, e.what()); - throw(e); // 继续抛到上层处理。 + throw(e); // 继续抛到上层处理? } } @@ -523,7 +523,7 @@ namespace hg_imgproc if (pid_ == 0x100 || pid_ == 0x200 || pid_ == 0x300 || pid_ == 0x400 || pid == 0x402 || pid == 0x302) { - //////除穿孔算法移至解压图像之后 + //////除穿孔算法移至解压图像之? double left = img_conf_.fillholeratio_left / 100.0; double right = img_conf_.fillholeratio_right / 100.0; double top = img_conf_.fillholeratio_up / 100.0; @@ -1336,7 +1336,7 @@ namespace hg_imgproc info.width = mats.cols; info.origin = HGBASE_IMGORIGIN_TOP; int bits = mats.channels() == 1 ? 8 : 24; - info.widthStep = mats.step; //opencv原始值 + info.widthStep = mats.step; //opencv原始? info.type = mats.channels() == 1 ? HGBASE_IMGTYPE_GRAY : HGBASE_IMGTYPE_BGR; int ret = HGBase_CreatImg(const_cast(mats.data), &info, &image); @@ -1348,11 +1348,11 @@ namespace hg_imgproc /// - /// 8位图转1位图 + /// 8位图?位图 /// - /// 8bit图 + /// 8bit?/param> /// 阈值,建议默认127 - /// true为反色,即黑0白1;反之亦然 + /// true为反色,即黑0?;反之亦?/param> /// true为四字节对齐 /// 1位图 /// @@ -1766,8 +1766,8 @@ namespace hg_imgproc return SCANNER_ERR_OPEN_FILE_FAILED; fseek(src, 0, SEEK_END); - len = ftell(src) - fh; - if (len <= 0) + len = ftell(src); + if (len <= fh + sizeof(bih)) { fclose(src); @@ -1777,7 +1777,7 @@ namespace hg_imgproc fseek(src, 0, SEEK_SET); fread(&bfh, sizeof(bfh), 1, src); fread(&bih, sizeof(bih), 1, src); - if (len < bfh.bfOffBits) + if (len < bfh.bfOffBits || len < bfh.bfSize) { fclose(src); @@ -1786,7 +1786,7 @@ namespace hg_imgproc // we consider pallete as gray, discard pallete here ... fseek(src, bfh.bfOffBits, SEEK_SET); - len -= bfh.bfOffBits; + // len -= bfh.bfOffBits; data.reset(new std::vector(len)); fread(&(*data.get())[0], 1, len, src); fclose(src); @@ -1854,7 +1854,9 @@ namespace hg_imgproc cpr.push_back(resolution_y); if (conv->dst.is_file) { - cv::imwrite(conv->dst.data, imsg, cpr); + std::string tmp(conv->dst.data); + cv::imwrite((tmp + ".jpg").c_str(), imsg, cpr); + rename((tmp + ".jpg").c_str(), tmp.c_str()); //FILE* f = fopen(conv->dst.data, "rb+"); //if (f) @@ -1867,7 +1869,7 @@ namespace hg_imgproc } else { - std::string tmpf(hg_log::temporary_path() + PATH_SEPARATOR + "imgtrans.tmp"); + std::string tmpf(hg_log::temporary_path() + PATH_SEPARATOR + "imgtrans.jpg"); cv::imwrite(tmpf.c_str(), imsg, cpr); size_t bytes = 0; conv->dst.data = (SANE_String_Const)G4Tiff::load_mini_file(tmpf.c_str(), &bytes, allocate_memory);