diff --git a/huagao/CTwainUI.cpp b/huagao/CTwainUI.cpp index 759319e3..36b5eb57 100644 --- a/huagao/CTwainUI.cpp +++ b/huagao/CTwainUI.cpp @@ -85,7 +85,7 @@ BOOL CTwainUI::OnInitDialog() UpdateUI(); UpdateListConfig(); dataChangeFunction(); - //setvisable_size(false); + setvisable_size(false); #ifdef G200 setvisable_sleepmode(false); #endif // G200 diff --git a/huagao/Device/GScanO1003399.cpp b/huagao/Device/GScanO1003399.cpp index 30a67081..be2e7dfb 100644 --- a/huagao/Device/GScanO1003399.cpp +++ b/huagao/Device/GScanO1003399.cpp @@ -246,7 +246,6 @@ void GScanO1003399::config_params(GScanCap& param) cfg.g200params.enable_sizecheck = param.en_sizecheck == 1 ? 1 : 0; cfg.g200params.unused_one = cfg.g200params.sizeerror_errorratio = 0; - param.resolution_dst >= 240.0f ? 1 : 0; #else @@ -271,12 +270,12 @@ void GScanO1003399::config_params(GScanCap& param) cfg.g400params.reversed1 = cfg.g400params.reversed2 = 0; #endif // G200 config_scanparam(cfg); - config_imgprocparam({0}); + config_imgprocparam({sizeof(GScanCap_3399)}); GScanCap_3399 param39{ 0 }; param39.AutoCrop_threshold = param.AutoCrop_threshold; param39.autodescrew = param.autodescrew; param39.automaticcolor = param.automaticcolor; - param39.automaticcolortype = param39.automaticcolortype; + param39.automaticcolortype = param.automaticcolortype; param39.brightness = param.brightness; param39.contrast = param.contrast; param39.detachnoise = param.detachnoise; @@ -312,6 +311,8 @@ void GScanO1003399::config_params(GScanCap& param) param39.scannum = param.scannum; param39.sharpen = param.sharpen; param39.threshold = param.threshold; + param39.multiOutput = MultiOutput::Unused; + param39.normalCrop = param.normalCrop; m_usb->write_bulk(¶m39, sizeof(param39)); } @@ -688,7 +689,7 @@ int GScanO1003399::read_data(void* data, int length, int timeout) StopWatch sw; FileTools::writelog(log_INFO, "read_data timeout =" + to_string(timeout)); while (readed < length) { - if (sw.elapsed_ms() < timeout) + if (sw.elapsed_ms() < timeout &&m_usb.get()) { reading = std::max(0, std::min(length - readed, buffer_size)); reading = m_usb->read_bulk((unsigned char*)data + readed, reading); diff --git a/huagao/Device/ImageMatQueue.cpp b/huagao/Device/ImageMatQueue.cpp index 3fbfbe43..7b963e1b 100644 --- a/huagao/Device/ImageMatQueue.cpp +++ b/huagao/Device/ImageMatQueue.cpp @@ -439,6 +439,11 @@ void ImageMatQueue::proc() while (bRun) { + if (m_imagedata.Size() > 0) + { + this_thread::sleep_for(chrono::milliseconds(10)); + continue; + } string msg; auto info = m_imgCacheinfo.Take(); if (info.path.length() == 0 || !isFileExist(info.path)) @@ -571,10 +576,14 @@ void ImageMatQueue::proc() mats[j].release(); break; } - cv::Mat mergeOrgin_UV = ImageApplyUV::Apply(mats[j], uvmats[j], rects[j], isDesaskew, angleResults.size() > 0 ? angleResults[j] : 0, scanParam.pixtype); - if (!mergeOrgin_UV.empty()) - mats[j] = mergeOrgin_UV; + if (!mats[j].empty()) + { + cv::Mat mergeOrgin_UV = ImageApplyUV::Apply(mats[j], uvmats[j], rects[j], isDesaskew, angleResults.size() > 0 ? angleResults[j] : 0, scanParam.pixtype); + if (!mergeOrgin_UV.empty()) + mats[j] = mergeOrgin_UV; + } } + rects.clear(); uvmats.clear(); } #endif diff --git a/huagao/Device/ImageMatQueue.h b/huagao/Device/ImageMatQueue.h index 122e783b..96b93109 100644 --- a/huagao/Device/ImageMatQueue.h +++ b/huagao/Device/ImageMatQueue.h @@ -54,7 +54,7 @@ public: setBmpInfoHeader(mat, res); //uchar* data = m_data->data() + headersize + bmpdatasize; //uchar* matdata = mat.data; - //for (int i = 0; i < mat.rows; i++){ + //for (int i = 0; i < mat.rows; i++) { // data -= m_datalinesize; // memcpy(data, matdata, step); // matdata += step; diff --git a/huagao/Device/PublicFunc.h b/huagao/Device/PublicFunc.h index 2522e748..5f24d597 100644 --- a/huagao/Device/PublicFunc.h +++ b/huagao/Device/PublicFunc.h @@ -146,7 +146,7 @@ typedef struct tagCONFIGINFO typedef struct tagFillHole { - byte is_fillhole; + uint8_t is_fillhole; int fillholeratio; }FillHole; @@ -181,6 +181,12 @@ typedef struct tagHARDWAREPARAMS #endif }HardwareCaps; +typedef struct tagSkew_Detection { + uint8_t enable; + int level; +}SkewDetection; + + typedef struct Scan_Rect { int width; int height; @@ -188,7 +194,7 @@ typedef struct Scan_Rect { int y; }ScanRect; -enum PaperAlign :uint8_t { +enum PaperAlign :unsigned char { Rot0 = 0, Rot270 = 3, AutoTextOrientation = 5 @@ -259,6 +265,23 @@ struct GScanCap std::string SavePath; }; +typedef struct tagCrop_Rect +{ + int enable; + int x; /*****×Ô¶¨Òå²ÃÇÐÇøÓò×óÉϽÇx×ø±ê*/ + int y; /*****×Ô¶¨Òå²ÃÇÐÇøÓò×óÉϽÇy×ø±ê*/ + int width; /*****×Ô¶¨Òå²ÃÇÐÇøÓò¿í¶È*******/ + int height; /*****×Ô¶¨Òå²ÃÇÐÇøÓò¸ß¶È*******/ +}CropRect; + +typedef enum tagMulti_Output { + Unused = -1, + All, + ColorGray, + ColorBw, + GrayBw +}MultiOutput; + struct GScanCap_3399 { @@ -298,10 +321,21 @@ struct GScanCap_3399 unsigned short scannum; /**< ɨÃèÕÅÊý*/ uint8_t is_backrotate180; /**< ±³ÃæÐýת180*/ uint8_t is_dogeardetection; /**<Õ۽Ǽì²â*/ - HardwareCaps hardwarecaps; /**< Ó²¼þɨÃè²ÎÊý*/ + HardwareCaps hardwarecaps; /**< Ó²¼þɨÃè²ÎÊý*/ FillHole fillhole; DetachNoise detachnoise; /**< ºÚ°×½µÔë*/ - uint8_t is_autotext; /**< ×Ô¶¯Îı¾·½Ïòʶ±ð*/ + uint8_t is_autotext; /**< ×Ô¶¯Îı¾·½Ïòʶ±ð*/ + bool isfillcolor; /**< ×Ô¶¯²ÃÇÐÑÕÉ«Ìî³ä>*/ + int refuseInflow; /**< ·ÀÖ¹Éø͸>*/ + int colorCorrection; /**< É«²ÊУÕý>*/ + int removeMorr; /**< È¥³ýĦ¶ûÎÆ>*/ + int errorExtention; /** < ´íÎóÀ©É¢>*/ + int textureRemove; /** < ³ýÍøÎÆ>*/ + int splitImage; /** < ͼÏñ²ð·Ö>*/ + CropRect cropRect; /**< ×Ô¶¨Òå²ÃÇÐ>*/ + MultiOutput multiOutput; /**< ¶àÁ÷Êä³ö>*/ + bool normalCrop; /**< ×Ô¶¯²ÃÇÐÉîÉ«ÑùÕÅ>*/ + uint32_t reserve[1024]; /**< Ô¤Áô4096×Ö½Ú×öЭÒéÀ©Õ¹*/ }; typedef struct Paper_Status { diff --git a/huagao/ImageProcess/ImageApplyAutoCrop.cpp b/huagao/ImageProcess/ImageApplyAutoCrop.cpp index b87a60ba..45af1f28 100644 --- a/huagao/ImageProcess/ImageApplyAutoCrop.cpp +++ b/huagao/ImageProcess/ImageApplyAutoCrop.cpp @@ -1,4 +1,4 @@ -#include "ImageApplyAutoCrop.h" +#include "ImageApplyAutoCrop.h" #include "ImageProcess_Public.h" CImageApplyAutoCrop::CImageApplyAutoCrop() @@ -33,16 +33,88 @@ CImageApplyAutoCrop::~CImageApplyAutoCrop() { } +cv::Mat concatenateMatrix(const cv::Mat& first, const cv::Mat& second) +{ + cv::Mat mul1 = cv::Mat::eye(3, 3, CV_64F); + cv::Mat mul2 = cv::Mat::eye(3, 3, CV_64F); + cv::Mat mul_r; + first.convertTo(mul_r, CV_64F); + mul_r.row(0).copyTo(mul1.row(0)); + mul_r.row(1).copyTo(mul1.row(1)); + + second.convertTo(mul_r, CV_64F); + mul_r.row(0).copyTo(mul2.row(0)); + mul_r.row(1).copyTo(mul2.row(1)); + + mul1 = mul2 * mul1; + mul_r = first.clone(); + mul1.row(0).copyTo(mul_r.row(0)); + mul1.row(1).copyTo(mul_r.row(1)); + return mul_r; +} + + +std::vector comMat() +{ + std::vector mats; + cv::Point2f srcTri[3]; + srcTri[0] = cv::Point2f(1, 1); + srcTri[1] = cv::Point2f(1, 0); + srcTri[2] = cv::Point2f(0, 1); + const float fact = 0.1f; + + float pos[] = { 0, 2 * fact, fact }; + cv::Point2f dstTri[3]; + dstTri[0] = cv::Point2f(1, 1); + dstTri[1] = cv::Point2f(1, 0.5); + dstTri[2] = cv::Point2f(0, 1); + + for (int i = 0; i < 3; i++) + { + dstTri[0] = cv::Point2f(1, 1 + pos[i]); + dstTri[1] = cv::Point2f(1, pos[i]); + dstTri[2] = cv::Point2f(0, 1 + pos[i]); + + mats.push_back(cv::getAffineTransform(srcTri, dstTri)); + } + return mats; +} + +void brightSharp(cv::Mat& src) +{ + const float a = -0.49f; + const float b = 3.0f; + //float kernel_data[] = { + // a, 0, 0, 0, a, + // 0, 0, a, 0, 0, + // 0, a, b, a, 0, + // 0, 0, a, 0, 0, + // a, 0, 0, 0, a }; + + float kernel_data[] = { + 0, a, 0, + a, b, a, + 0, a, 0 + }; + cv::Mat kernel(3, 3, CV_32FC1, kernel_data); + cv::filter2D(src, src, src.depth(), kernel); +} + void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side) { (void)side; if (pDib.empty()) return; - if (!m_isCrop && !m_isDesaskew && !m_isFillBlank && m_normalCrop/* && m_fixedSize.empty()*/) + + if (m_normalCrop) { - pDib = pDib(cv::Rect((pDib.cols - m_fixedSize.width) / 2, side == 0 ? 75 : 145, m_fixedSize.width, m_fixedSize.height) & cv::Rect(0, 0, pDib.cols, pDib.rows)).clone(); + cv::Rect roi = cv::Rect((pDib.cols - m_fixedSize.width) / 2, side == 0 ? 75 : 145, m_fixedSize.width, m_fixedSize.height) & cv::Rect(0, 0, pDib.cols, pDib.rows); + pDib = pDib(roi).clone(); + m_rect = cv::RotatedRect(cv::Point2f(roi.x + roi.width / 2, roi.y + roi.height / 2), cv::Size2f(roi.width, roi.height), 0.0f); return; } + if (!m_isCrop && !m_isDesaskew && !m_isFillBlank && m_fixedSize.empty()) return; + cv::Mat src = pDib; cv::Mat thre; cv::Mat dst; @@ -62,7 +134,7 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side) if (m_maxContour.size() == 0) { thre.release(); - //Èç¹ûÊǹ̶¨·ùÃ棬Ðë·µ»Ø²ÃÇкóµÄ³ß´ç + //����ǹ̶����棬�뷵�ز��к�ijߴ� if (!m_isCrop) pDib = pDib(cv::Rect((pDib.cols - m_fixedSize.width) / 2, (pDib.rows - m_fixedSize.height) / 2, m_fixedSize.width, m_fixedSize.height) & cv::Rect(0, 0, pDib.cols, pDib.rows)).clone(); #ifdef LOG @@ -75,7 +147,6 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side) cv::RotatedRect rect = hg::getBoundingRect(m_maxContour); m_rect = rect; - cv::Rect boudingRect = cv::boundingRect(m_maxContour); boudingRect.x -= 1; boudingRect.y -= 1; @@ -84,30 +155,76 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side) if (m_isDesaskew && rect.angle != 0) { - cv::Point2f srcTri[4]; - cv::Point2f dstTri[3]; + cv::Point2f srcTri[4], srcTri_temp[3], dstTri[3]; rect.points(srcTri); - for (cv::Point2f& p : srcTri) - { - p.x -= 0.5; - p.y -= 0.5; - } dstTri[0] = cv::Point2f(0, rect.size.height - 1); dstTri[1] = cv::Point2f(0, 0); dstTri[2] = cv::Point2f(rect.size.width - 1, 0); + + srcTri_temp[0] = dstTri[0]; + srcTri_temp[1] = dstTri[1]; + srcTri_temp[2] = dstTri[2]; cv::Mat warp_mat; warp_mat = cv::getAffineTransform(srcTri, dstTri); - cv::warpAffine(src, dst, warp_mat, rect.size, cv::INTER_LINEAR); + if (src.channels() == 1) + { + cv::warpAffine(src, dst, warp_mat, rect.size, cv::INTER_LINEAR); + } + else + { + cv::Mat bgr[3]; + cv::split(src, bgr); + auto mats = comMat(); + warp_mat = cv::getAffineTransform(srcTri, dstTri); + warp_mat = concatenateMatrix(mats[0], warp_mat); + //warp_mat = mats[0]; + + cv::warpAffine(bgr[0], bgr[0], warp_mat, rect.size, cv::INTER_LINEAR); + + warp_mat = cv::getAffineTransform(srcTri, dstTri); + warp_mat = concatenateMatrix(mats[1], warp_mat); + //warp_mat = mats[1]; + cv::warpAffine(bgr[1], bgr[1], warp_mat, rect.size, cv::INTER_LINEAR); + + warp_mat = cv::getAffineTransform(srcTri, dstTri); + warp_mat = concatenateMatrix(mats[2], warp_mat); + //warp_mat = mats[2]; + cv::warpAffine(bgr[2], bgr[2], warp_mat, rect.size, cv::INTER_LINEAR); + + cv::merge(bgr, 3, dst); + } + + double* ptr_m = reinterpret_cast(warp_mat.data); + double a = ptr_m[0]; + double b = ptr_m[1]; + double c = ptr_m[2]; + double d = ptr_m[3]; + double e = ptr_m[4]; + double f = ptr_m[5]; + + for (cv::Point& p : m_maxContour) + { + p.x = static_cast(a * p.x + b * p.y + c); + p.y = static_cast(d * p.x + e * p.y + f); + } } else - dst = src(boudingRect & cv::Rect(0, 0, src.cols, src.rows)); - - m_maxContour.clear(); - m_maxContour.push_back(cv::Point(-1, dst.rows)); - m_maxContour.push_back(cv::Point(-1, -1)); - m_maxContour.push_back(cv::Point(dst.cols, -1)); - m_maxContour.push_back(cv::Point(dst.cols, dst.rows)); + { + auto t_rect = boudingRect & cv::Rect(0, 0, src.cols, src.rows); + dst = src(t_rect); + if (dst.channels() == 3) + { + cv::Mat bgr[3]; + cv::split(dst, bgr); + auto mats = comMat(); + for (int i = 0; i < 3; i++) + { + cv::warpAffine(bgr[i], bgr[i], mats[i], t_rect.size(), cv::INTER_LINEAR); + } + cv::merge(bgr, 3, dst); + } + } cv::Scalar autoBGColor; @@ -118,21 +235,31 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side) if (m_indent > 0) { - std::vector rectEdge{ cv::Point(0, 0) ,cv::Point(thre_dst.cols - 1, 0), - cv::Point(thre_dst.cols - 1, thre_dst.rows - 1), cv::Point(0, thre_dst.rows - 1) }; - std::vector> rectEdges{ rectEdge }; - cv::drawContours(thre_dst, rectEdges, 0, cv::Scalar::all(0)); - cv::Mat element = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(m_indent, m_indent)); - cv::erode(thre_dst, thre_dst, element, cv::Point(-1, -1), 1); + for (size_t i = 0, length = m_maxContour.size() - 1; i < length; i++) + cv::line(thre_dst, m_maxContour[i], m_maxContour[i + 1], cv::Scalar::all(0), m_indent * 2); + cv::line(thre_dst, *m_maxContour.begin(), *m_maxContour.rbegin(), cv::Scalar::all(0), m_indent * 2); } + + //cv::imwrite("abc.jpg", thre_dst); hierarchy.clear(); contours.clear(); m_maxContour.clear(); - hg::findContours(thre_dst, contours, hierarchy, cv::RETR_EXTERNAL); if (m_isConvexHull) { m_maxContour = hg::getMaxContour(contours, hierarchy); + + if (m_maxContour.size() == 0) + { + thre.release(); + //����ǹ̶����棬�뷵�ز��к�ijߴ� + if (!m_isCrop) + pDib = pDib(cv::Rect((pDib.cols - m_fixedSize.width) / 2, (pDib.rows - m_fixedSize.height) / 2, m_fixedSize.width, m_fixedSize.height) & cv::Rect(0, 0, pDib.cols, pDib.rows)).clone(); +#ifdef LOG + FileTools::write_log("imgprc.txt", "exit CImageApplyAutoCrop apply"); +#endif // LOG + return; + } hg::convexHull(m_maxContour, m_maxContour); contours.clear(); contours.push_back(m_maxContour); @@ -147,6 +274,14 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side) autoBGColor = m_isFillColor ? getBackGroudColor(pDib, rect.size.area()) : cv::Scalar(255, 255, 255); hg::fillPolys(dst, contours, autoBGColor); } + else + { + m_maxContour.clear(); + m_maxContour.push_back(cv::Point(-1, dst.rows)); + m_maxContour.push_back(cv::Point(-1, -1)); + m_maxContour.push_back(cv::Point(dst.cols, -1)); + m_maxContour.push_back(cv::Point(dst.cols, dst.rows)); + } pDib.release(); if (/*(m_isCrop && side == 0) || (side == 1 && m_fixedSize.width * m_fixedSize.height == 0)*/ m_isCrop) @@ -166,16 +301,20 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side) p += roi.tl(); dst(roi).copyTo(pDib(rect)); } +#ifdef LOG + FileTools::write_log("imgprc.txt", "exit CImageApplyAutoCrop apply8"); +#endif // LOG } + + void CImageApplyAutoCrop::apply(std::vector& mats, bool isTwoSide) { - m_rects.clear(); if (mats.empty()) return; if (!mats[0].empty()) { apply(mats[0], 0); m_rects.push_back(m_rect); - //cv::imwrite("1.bmp", mats[0]); + brightSharp(mats[0]); } if (isTwoSide && mats.size() > 1) @@ -186,6 +325,7 @@ void CImageApplyAutoCrop::apply(std::vector& mats, bool isTwoSide) if (!mats[1].empty()) { apply(mats[1], 1); m_rects.push_back(m_rect); + brightSharp(mats[1]); } if (!mats[0].empty()) diff --git a/huagao/ImageProcess/ImageApplyUV.cpp b/huagao/ImageProcess/ImageApplyUV.cpp index 779d633b..56808fe6 100644 --- a/huagao/ImageProcess/ImageApplyUV.cpp +++ b/huagao/ImageProcess/ImageApplyUV.cpp @@ -55,7 +55,8 @@ void ImageApplyUV::Apply(cv::Mat& image, const cv::Mat& uv, int dpi, int thresh) cv::Mat ImageApplyUV::Apply(const cv::Mat& image, const cv::Mat& uv, const cv::RotatedRect& uvRoi, bool isDesaskew, int angle, int pixtype) { static int svindex = 0; - if (uvRoi.size.width == 0) return cv::Mat(); + if (uvRoi.size.width == 0) + return cv::Mat(); cv::RotatedRect uvRoi_clone = uvRoi; cv::Mat dst = cv::Mat::zeros(image.rows > image.cols ? image.rows : (image.rows * 2), image.cols > image.rows ? image.cols : (image.cols * 2), image.type()); image.copyTo(dst(cv::Rect(0, 0, image.cols, image.rows))); @@ -70,54 +71,76 @@ cv::Mat ImageApplyUV::Apply(const cv::Mat& image, const cv::Mat& uv, const cv::R if (angle == 90) { dstTri[0] = cv::Point2f(0, 0); - dstTri[1] = cv::Point2f(dst_uv.cols - 1, 0); - dstTri[2] = cv::Point2f(dst_uv.cols - 1, dst_uv.rows - 1); + dstTri[1] = cv::Point2f(uvRoi_clone.size.width - 1, 0); + dstTri[2] = cv::Point2f(uvRoi_clone.size.width - 1, uvRoi_clone.size.height - 1); } else if (angle == 180) { - dstTri[0] = cv::Point2f(dst_uv.cols - 1, 0); - dstTri[1] = cv::Point2f(dst_uv.cols - 1, dst_uv.rows - 1); - dstTri[2] = cv::Point2f(0, dst_uv.rows - 1); + dstTri[0] = cv::Point2f(uvRoi_clone.size.width - 1, 0); + dstTri[1] = cv::Point2f(uvRoi_clone.size.width - 1, uvRoi_clone.size.height - 1); + dstTri[2] = cv::Point2f(0, uvRoi_clone.size.height - 1); } else if (angle == 270) { - dstTri[0] = cv::Point2f(dst_uv.cols - 1, dst_uv.rows - 1); - dstTri[1] = cv::Point2f(0, dst_uv.rows - 1); + dstTri[0] = cv::Point2f(uvRoi_clone.size.width - 1, uvRoi_clone.size.height - 1); + dstTri[1] = cv::Point2f(0, uvRoi_clone.size.height - 1); dstTri[2] = cv::Point2f(0, 0); } else { - dstTri[0] = cv::Point2f(0, dst_uv.rows - 1); + dstTri[0] = cv::Point2f(0, uvRoi_clone.size.height - 1); dstTri[1] = cv::Point2f(0, 0); - dstTri[2] = cv::Point2f(dst_uv.cols - 1, 0); + dstTri[2] = cv::Point2f(uvRoi_clone.size.width - 1, 0); } cv::Mat warp_mat = cv::getAffineTransform(srcTri, dstTri); - if (uv.channels() == 1 && dst_uv.channels() == 3) + cv::Mat uv_temp; + cv::warpAffine(uv, uv_temp, warp_mat, cv::Size(uvRoi_clone.size.width, uvRoi_clone.size.height)); + + //cv::imwrite("uv_temp.jpg", uv_temp); + if (pixtype == 0)//¶þֵͼ { - cv::Mat uv_temp; - cv::warpAffine(uv, uv_temp, warp_mat, dst_uv.size()); - cv::cvtColor(uv_temp, dst_uv, cv::COLOR_GRAY2BGR); + cvtColor(uv_temp, uv_temp, cv::COLOR_BGR2GRAY); + cv::threshold(uv_temp, uv_temp, 150, 255, THRESH_OTSU); + } + + if (uv_temp.channels() == 1 && dst_uv.channels() == 3) + { + cv::cvtColor(uv_temp(cv::Rect( + uv_temp.cols > dst_uv.cols ? (uv_temp.cols - dst_uv.cols) / 2 : 0, + uv_temp.rows > dst_uv.rows ? (uv_temp.rows - dst_uv.rows) / 2 : 0, + uv_temp.cols > dst_uv.cols ? dst_uv.cols : uv_temp.cols, + uv_temp.rows > dst_uv.rows ? dst_uv.rows : uv_temp.rows)), + dst_uv(cv::Rect( + dst_uv.cols > uv_temp.cols ? (dst_uv.cols - uv_temp.cols) / 2 : 0, + dst_uv.rows > uv_temp.rows ? (dst_uv.rows - uv_temp.rows) / 2 : 0, + dst_uv.cols > uv_temp.cols ? uv_temp.cols : dst_uv.cols, + dst_uv.rows > uv_temp.rows ? uv_temp.rows : dst_uv.rows)), cv::COLOR_GRAY2BGR); + } + else if (uv_temp.channels() == 3 && dst_uv.channels() == 1) + { + cv::cvtColor(uv_temp(cv::Rect( + uv_temp.cols > dst_uv.cols ? (uv_temp.cols - dst_uv.cols) / 2 : 0, + uv_temp.rows > dst_uv.rows ? (uv_temp.rows - dst_uv.rows) / 2 : 0, + uv_temp.cols > dst_uv.cols ? dst_uv.cols : uv_temp.cols, + uv_temp.rows > dst_uv.rows ? dst_uv.rows : uv_temp.rows)), + dst_uv(cv::Rect( + dst_uv.cols > uv_temp.cols ? (dst_uv.cols - uv_temp.cols) / 2 : 0, + dst_uv.rows > uv_temp.rows ? (dst_uv.rows - uv_temp.rows) / 2 : 0, + dst_uv.cols > uv_temp.cols ? uv_temp.cols : dst_uv.cols, + dst_uv.rows > uv_temp.rows ? uv_temp.rows : dst_uv.rows)), cv::COLOR_BGR2GRAY); } else { - //imwrite("D:\\bfuv" + std::to_string(++svindex) + ".jpg", uv); - cv::Mat matuv; - if (image.channels() == 1 && uv.channels() == 3) - { - cvtColor(uv, matuv, COLOR_BGR2GRAY); - if (pixtype == 0)//¶þֵͼ - cv::threshold(matuv, matuv, 150, 255, THRESH_OTSU); - } - else - { - matuv = uv; - } - - cv::warpAffine(matuv, dst_uv, warp_mat, dst_uv.size()); - //dst_uv.copyTo(dst(cv::Rect(image.rows > image.cols ? image.cols : 0, image.rows > image.cols ? 0 : image.rows, dst_uv.cols, dst_uv.rows))); - //dst_uv.copyTo(dst(cv::Rect(image.rows > image.cols ? image.cols : 0, image.rows > image.cols ? 0 : image.rows, image.cols, image.rows))); - //imwrite("D:\\aftuv" + std::to_string(svindex) + ".jpg", dst_uv); + uv_temp(cv::Rect( + uv_temp.cols > dst_uv.cols ? (uv_temp.cols - dst_uv.cols) / 2 : 0, + uv_temp.rows > dst_uv.rows ? (uv_temp.rows - dst_uv.rows) / 2 : 0, + uv_temp.cols > dst_uv.cols ? dst_uv.cols : uv_temp.cols, + uv_temp.rows > dst_uv.rows ? dst_uv.rows : uv_temp.rows)).copyTo(dst_uv(cv::Rect( + dst_uv.cols > uv_temp.cols ? (dst_uv.cols - uv_temp.cols) / 2 : 0, + dst_uv.rows > uv_temp.rows ? (dst_uv.rows - uv_temp.rows) / 2 : 0, + dst_uv.cols > uv_temp.cols ? uv_temp.cols : dst_uv.cols, + dst_uv.rows > uv_temp.rows ? uv_temp.rows : dst_uv.rows))); } } diff --git a/huagao/ImageProcess/ImageProcess_Public.cpp b/huagao/ImageProcess/ImageProcess_Public.cpp index 1d931005..70965709 100644 --- a/huagao/ImageProcess/ImageProcess_Public.cpp +++ b/huagao/ImageProcess/ImageProcess_Public.cpp @@ -204,6 +204,14 @@ namespace hg rect.size.height = temp; } + if (rect.angle > 45) + { + rect.angle -= 90; + float temp = rect.size.width; + rect.size.width = rect.size.height; + rect.size.height = temp; + } + return rect; } diff --git a/huagao/huagaods.cpp b/huagao/huagaods.cpp index f216e046..e38ae8e0 100644 --- a/huagao/huagaods.cpp +++ b/huagao/huagaods.cpp @@ -86,7 +86,7 @@ using namespace std::placeholders; TWPP_ENTRY_MFC(HuagaoDs) static constexpr const Identity srcIdent( - Version(3, 3, Language::English, Country::China, "v3.3.5.1"), + Version(3, 3, Language::English, Country::China, "v3.3.5.4"), DataGroup::Image, #ifdef MAKEHUAGAO "HUAGO", diff --git a/huagao/huagaotwds.rc b/huagao/huagaotwds.rc index 9163e816..6174d014 100644 Binary files a/huagao/huagaotwds.rc and b/huagao/huagaotwds.rc differ diff --git a/huagao/stdafx.h b/huagao/stdafx.h index 9cdef02f..a01afd12 100644 Binary files a/huagao/stdafx.h and b/huagao/stdafx.h differ