92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "layer.h"
|
|
#include "net.h"
|
|
#include <iostream>
|
|
#include <opencv2/core/core.hpp>
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
#include <float.h>
|
|
#include <stdio.h>
|
|
#include <vector>
|
|
#include <time.h>
|
|
#include "algorithm"
|
|
#include "vector"
|
|
#include <fstream>
|
|
#include <regex>
|
|
#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<Object>& faceobjects, int left, int right);
|
|
void qsort_descent_inplace(std::vector<Object>& objects);
|
|
void nms_sorted_bboxes(const std::vector<Object>& faceobjects, std::vector<int>& picked, float nms_threshold);
|
|
void generate_grids_and_stride(const int target_size, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides);
|
|
void generate_yolox_proposals(std::vector<GridAndStride> grid_strides, const ncnn::Mat& feat_blob, float prob_threshold, std::vector<Object>& objects);
|
|
|
|
std::vector<Character> nms(std::vector<Character> &chars);
|
|
std::string cluster(std::vector<Character> &chars, std::string mode, bool& isModeCorrect);
|
|
bool isOverlaped(cv::Rect rect1, cv::Rect rect2);
|
|
std::vector<std::string> splitOCR(std::string rawOcr);
|
|
std::vector<std::string> splitString(const std::string& s, const std::string& c);
|
|
|
|
std::vector<ObjectDetect> 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;
|
|
}; |