#pragma once #include "layer.h" #include "net.h" #include #include #include #include #include #include #include #include #include "algorithm" #include "vector" #include #include #include "config.h" class YoloV5FocusCharacterDetection : public ncnn::Layer { public: YoloV5FocusCharacterDetection() { one_blob_only = true; } virtual int forward(const ncnn::Mat& bottom_blob, ncnn::Mat& top_blob, const ncnn::Option& opt) const { int w = bottom_blob.w; int h = bottom_blob.h; int channels = bottom_blob.c; int outw = w / 2; int outh = h / 2; int outc = channels * 4; top_blob.create(outw, outh, outc, 4u, 1, opt.blob_allocator); if (top_blob.empty()) return -100; #pragma omp parallel for num_threads(opt.num_threads) for (int p = 0; p < outc; p++) { const float* ptr = bottom_blob.channel(p % channels).row((p / channels) % 2) + ((p / channels) / 2); float* outptr = top_blob.channel(p); for (int i = 0; i < outh; i++) { for (int j = 0; j < outw; j++) { *outptr = *ptr; outptr += 1; ptr += 2; } ptr += w; } } return 0; } }; class CharacterDetector{ public: CharacterDetector(); inline float intersection_area(const Object& a, const Object& b); void qsort_descent_inplace(std::vector& faceobjects, int left, int right); void qsort_descent_inplace(std::vector& objects); void nms_sorted_bboxes(const std::vector& faceobjects, std::vector& picked, float nms_threshold); void generate_grids_and_stride(const int target_size, std::vector& strides, std::vector& grid_strides); void generate_yolox_proposals(std::vector grid_strides, const ncnn::Mat& feat_blob, float prob_threshold, std::vector& objects); std::vector nms(std::vector &chars); std::string cluster(std::vector &chars, std::string mode, bool& isModeCorrect); bool isOverlaped(cv::Rect rect1, cv::Rect rect2); std::vector splitOCR(std::string rawOcr); std::vector splitString(const std::string& s, const std::string& c); std::vector Detect(cv::Mat frame); std::string extract(cv::Mat rawPlate, std::string mode); private: float minWidth = 15; int useRuleHead = 0; int useRuleMid = 0; int useRuleTail = 0; ncnn::Net net; float yolox_nms_thresh = 0.3; float yolox_conf_thresh = 0.3; int yolox_target_size = 416; };