From b8918b123db31cfd97faf6bfeec03372c7748685 Mon Sep 17 00:00:00 2001 From: "y.qiu" Date: Fri, 6 Sep 2024 14:35:08 +0800 Subject: [PATCH] static check --- grayMatch.cpp | 29 ++++++++++++++++------------- grayMatch.h | 16 ++++++++-------- serialize.cpp | 4 +++- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/grayMatch.cpp b/grayMatch.cpp index 1194ec4..fd9a2b1 100644 --- a/grayMatch.cpp +++ b/grayMatch.cpp @@ -203,15 +203,16 @@ cv::Size computeRotationSize(const cv::Size &dstSize, const cv::Size &templateSi (templateSize.width > size.width && templateSize.height < size.height) || templateSize.area() > size.area(); if (wrongSize) { - size = {static_cast(max.x - min.x + 0.5), static_cast(max.y - min.y + 0.5)}; + size = {static_cast(lround(max.x - min.x + 0.5)), + static_cast(lround(max.y - min.y + 0.5))}; } return size; } -void coeffDenominator(const cv::Mat &src, const cv::Size &templateSize, cv::Mat &result, - const double mean, const double normal, const double invArea, - const bool equal1) { +void ccoeffDenominator(const cv::Mat &src, const cv::Size &templateSize, cv::Mat &result, + const double mean, const double normal, const double invArea, + const bool equal1) { if (equal1) { result = cv::Scalar::all(1); return; @@ -286,6 +287,7 @@ void matchTemplateSimd(const cv::Mat &src, const cv::Mat &templateImg, cv::Mat & } } +/* void matchTemplateSimd2(const cv::Mat &src, const cv::Mat &templateImg, cv::Mat &result) { auto size = src.size() - templateImg.size() + cv::Size(1, 1); auto alignedWidth = static_cast(cv::alignSize(size.width, cv::v_uint8::nlanes)); @@ -347,6 +349,7 @@ void matchTemplateSimd2(const cv::Mat &src, const cv::Mat &templateImg, cv::Mat } } } +*/ #endif @@ -356,8 +359,8 @@ void matchTemplate(cv::Mat &src, cv::Mat &result, const Model *model, int level) #else cv::matchTemplate(src, model->pyramids[ level ], result, cv::TM_CCORR); #endif - coeffDenominator(src, model->pyramids[ level ].size(), result, model->mean[ level ][ 0 ], - model->normal[ level ], model->invArea[ level ], model->equal1[ level ] == 1); + ccoeffDenominator(src, model->pyramids[ level ].size(), result, model->mean[ level ][ 0 ], + model->normal[ level ], model->invArea[ level ], model->equal1[ level ] == 1); } void nextMaxLoc(const cv::Point &pos, const cv::Size templateSize, const double maxOverlap, @@ -756,14 +759,14 @@ std::vector matchModel(const cv::Mat &dst, const Model *model, int level, return result; } -Model_t trainModel(const unsigned char *data, int width, int height, int channels, int bytesPerline, +Model_t trainModel(const unsigned char *data, int width, int height, int channels, int bytesPerLine, int roiLeft, int roiTop, int roiWidth, int roiHeight, int levelNum) { if ((1 != channels && 3 != channels && 4 != channels) || nullptr == data) { return nullptr; } auto type = channels == 1 ? CV_8UC1 : (channels == 3 ? CV_8UC3 : CV_8UC4); - cv::Mat img(cv::Size(width, height), type, (void *)data, bytesPerline); + cv::Mat img(cv::Size(width, height), type, const_cast(data), bytesPerLine); cv::Mat src; if (1 == channels) { @@ -782,8 +785,8 @@ Model_t trainModel(const unsigned char *data, int width, int height, int channel return trainModel(src(roi), levelNum); } -void matchModel(const unsigned char *data, int width, int height, int channels, int bytesPerline, - int roiLeft, int roiTop, int roiWidth, int roiHeight, const Model_t model, +void matchModel(const unsigned char *data, int width, int height, int channels, int bytesPerLine, + int roiLeft, int roiTop, int roiWidth, int roiHeight, const Model *model, int *count, Pose *poses, int level, double startAngle, double spanAngle, double maxOverlap, double minScore, int subpixel) { if (nullptr == count) { @@ -801,7 +804,7 @@ void matchModel(const unsigned char *data, int width, int height, int channels, } auto type = channels == 1 ? CV_8UC1 : (channels == 3 ? CV_8UC3 : CV_8UC4); - cv::Mat img(cv::Size(width, height), type, (void *)data, bytesPerline); + cv::Mat img(cv::Size(width, height), type, const_cast(data), bytesPerLine); cv::Mat dst; if (1 == channels) { @@ -840,7 +843,7 @@ void freeModel(Model_t *model) { *model = nullptr; } -int modelLevel(const Model_t model) { +int modelLevel(const Model *model) { if (nullptr == model) { return 0; } @@ -848,7 +851,7 @@ int modelLevel(const Model_t model) { return static_cast(model->pyramids.size()); } -void modelImage(const Model_t model, int level, unsigned char *data, int length, int *width, +void modelImage(const Model *model, int level, unsigned char *data, int length, int *width, int *height, int *channels) { if (nullptr == model) { return; diff --git a/grayMatch.h b/grayMatch.h index 1307a14..a96a60a 100644 --- a/grayMatch.h +++ b/grayMatch.h @@ -20,7 +20,7 @@ struct Pose { * @param width image width * @param height image height * @param channels image channels 1(gray)/3(rgb)/4(rgba) - * @param bytesPerline bytes per line + * @param bytesPerLine bytes per line * @param roiLeft rectangle roi left * @param roiTop rectangle roi top * @param roiWidth rectangle roi width @@ -29,7 +29,7 @@ struct Pose { * @return */ API_PUBLIC Model_t trainModel(const unsigned char *data, int width, int height, int channels, - int bytesPerline, int roiLeft, int roiTop, int roiWidth, + int bytesPerLine, int roiLeft, int roiTop, int roiWidth, int roiHeight, int levelNum); /** * @brief match model @@ -37,7 +37,7 @@ API_PUBLIC Model_t trainModel(const unsigned char *data, int width, int height, * @param width image width * @param height image height * @param channels image channels 1(gray)/3(rgb)/4(rgba) - * @param bytesPerline bytes per line + * @param bytesPerLine bytes per line * @param roiLeft rectangle roi left * @param roiTop rectangle roi top * @param roiWidth rectangle roi width @@ -54,8 +54,8 @@ API_PUBLIC Model_t trainModel(const unsigned char *data, int width, int height, * @return */ API_PUBLIC void matchModel(const unsigned char *data, int width, int height, int channels, - int bytesPerline, int roiLeft, int roiTop, int roiWidth, int roiHeight, - const Model_t model, int *count, Pose *poses, int level, + int bytesPerLine, int roiLeft, int roiTop, int roiWidth, int roiHeight, + const Model* model, int *count, Pose *poses, int level, double startAngle, double spanAngle, double maxOverlap, double minScore, int subpixel); @@ -64,7 +64,7 @@ API_PUBLIC void matchModel(const unsigned char *data, int width, int height, int * @param model * @return pyramid level */ -API_PUBLIC int modelLevel(const Model_t model); +API_PUBLIC int modelLevel(const Model* model); /** * @brief get trained model image @@ -77,7 +77,7 @@ API_PUBLIC int modelLevel(const Model_t model); * @param channels image channels, can input nullptr * @return */ -API_PUBLIC void modelImage(const Model_t model, int level, unsigned char *data, int length, +API_PUBLIC void modelImage(const Model* model, int level, unsigned char *data, int length, int *width, int *height, int *channels); /** @@ -94,7 +94,7 @@ API_PUBLIC void freeModel(Model_t *model); * @param size in(buffer size)/out(written size) * @return true(success)false(failed) */ -API_PUBLIC bool serialize(const Model_t model, unsigned char *buffer, int *size); +API_PUBLIC bool serialize(const Model* model, unsigned char *buffer, int *size); /** * @brief deserialize model diff --git a/serialize.cpp b/serialize.cpp index 5db2b88..65158d6 100644 --- a/serialize.cpp +++ b/serialize.cpp @@ -9,6 +9,8 @@ public: : m_size(size_) , m_data(data_) {} + virtual ~Buffer() = default; + virtual void operator&(uchar &val) = 0; virtual void operator&(std::vector &val) = 0; virtual void operator&(std::vector &val) = 0; @@ -185,7 +187,7 @@ void operation(Buffer *buf, Model &model) { (*buf) & (model); } -bool serialize(const Model_t model, unsigned char *buffer, int *size) { +bool serialize(Model *const model, unsigned char *buffer, int *size) { if (nullptr == size) { return false; }