admin
2023-03-07 8b06b1cbf112d55307ea8a6efe711db4e7506d89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<CL/cl.h>
#include "ImgUtil.h"
 
enum SplitType {
    NUM_TYPE_TIME,
    NUM_TYPE_MONEY,
    NUM_TYPE_PRICE,
    NUM_TYPE_CODE,
    NUM_TYPE_NUM,
    NUM_TYPE_PERCENT,
    NUM_TYPE_NUM_SHOU,
 
};
 
struct IntDataInfo
{
    int* data;
    int length;
};
 
struct UcharDataInfo
{
    uchar* data;
    int length;
};
 
class OpenCLExcuter
{
private:
    cl_int error;
    cl_uint num_of_platforms = 0;
    cl_platform_id platforms;
 
    cl_device_id devices;
 
    cl_context context;
 
    FILE* program_handle;
    size_t program_size;
    char* program_buffer;
    cl_program program;
 
    size_t log_size;
    char* program_log;
 
    cl_kernel kernel;
 
    cl_command_queue queue;
 
    //ÖØÐ´´½¨¶ÓÁÐ
    void reCreateQueue();
    //Ö´Ðгö´í
    void excuteError();
 
public:
    static string rootPath;
    void init();
    void destory();
 
 
    //½«RGBͼƬתΪ»Ò¶ÈͼƬ
    void rgb2Gray(cv::Mat img,
        unsigned char* result);
 
    //½«RGBAͼƬתΪ»Ò¶ÈͼƬ
    void rgba2Gray(cv::Mat img,
        unsigned char* result);
 
    //½«RGBͼƬ·´×ª¶þÖµ»¯»Ò¶ÈͼƬ
    void rgb2ThresholdInvert(unsigned char* imgs, int imgWidth, int imgHeight,
        unsigned char* result, int threadhold);
 
    //½«RGBAͼƬ·´×ª¶þÖµ»¯»Ò¶ÈͼƬ
    void rgba2ThresholdInvert(unsigned char* imgs, int imgWidth, int imgHeight,
        unsigned char* result, int threadhold);
 
 
    //´´½¨Ê¶±ðµÄÊý×ÖÄ£°å
    void createNumberTemplates(int lines, int num_width, int num_height, int num_count, uchar* numsOneLevelData, unsigned char* result);
    
    // Ê¶±ðÊý×Ö£ºÊ¶±ðµÄ¹æÔòΪdataÊý¾ÝÓënum_templates×ö¶Ô±È£¬´Ó¶øÊ¶±ð³ö°¢À­²®Êý×Ö
    // data Êý×ÖÊý¾Ý
    // num_templates Ê¶±ðµÄÄ£°å£¬³¤¶ÈµÈÓÚdataµÄ³¤¶È
    // rows£¬cols Õû¸ödata Ô­Ê¼¶þάÊý×éµÄ³¤¿í
    // num_width,num_heightÄ£°åÊý×ֵijߴç
    // line_number_count  Ã¿Ò»ÐÐÔªËØµÄ×ܵÄÊý×Ö¸öÊý
    unsigned char** recognition_numbers(unsigned char* data, unsigned char* num_templates, const int rows, const int cols, const int num_width, const int num_height, const int line_number_count);
 
    //·Ö¸ôÿһÐÐÐèҪʶ±ðµÄÊý×Ö
    //½«Á¬ÐøµÄÊý×ÖͼƬ·Ö¸ô³Éµ¥¸öÊý×ÖµÄͼƬ£¬·½±ãʶ±ð
    void splitL2Num(unsigned char* img, int img_width, int img_height, int* pos, int pos_count, unsigned char* zero, int num_width, int num_height, int number_count, unsigned char* result);
 
 
    //·Ö¸ô°å¿éÊý×Ö,ͨÓÃ
    void splitPlateNum(cv::Mat img, IntDataInfo pos, UcharDataInfo result, UcharDataInfo types, unsigned char* zero, int num_width, int num_height, int ele_count_per_line, int length_per_num);
 
 
    void splitL2NumNew(cv::Mat img, IntDataInfo pos, UcharDataInfo result, UcharDataInfo types, unsigned char* zero, int num_width, int num_height, int ele_count_per_line, int length_per_num);
 
    void splitTradeQueueNum(cv::Mat img, IntDataInfo pos, UcharDataInfo result, UcharDataInfo types, unsigned char* zero, int num_width, int num_height, int ele_count_per_line, int length_per_num);
 
 
 
    //·Ö¸ô°å¿éÊý×Ö
    void splitPlateNum(unsigned char* img, int img_width, int img_height, int* pos, int pos_count, unsigned char* zero, int num_width, int num_height, int number_count, unsigned char* result);
 
    //·Ö¸ô½»Ò×¶ÓÁÐÊý×Ö
    void splitTradeQueueNum(cv::Mat img, IntDataInfo pos, unsigned char* zero, int num_width, int num_height, unsigned char* result, int length_per_num);
 
 
    //·Ö¸ôÐÐÊý¾Ý
    //ÿһÐеÄÊý¾Ý·Ö¸ô³É7¸öÇøÓò
    void splitL2RowData(cv::Mat img, int* rowIndexs, int lines,
        int* result);
 
    void splitRowData(cv::Mat img, int* rowIndexs, int lines,int ele_count_per_line,
        int* result);
 
    void splitPlateContentRowData(unsigned char* imgs, int imgWidth, int imgHeight, int* rowIndexs, int lines, int lineEleCount,int fromIndex,int toIndex,
        int* result);
 
    //ʶ±ð·ÇÊý×Ö
    void recognitionNotNum(unsigned char* imgs, int imgWidth, int imgHeight, int* rowIndexs, int colEleCount, int lines,
        int* result);
 
    void recognitionPlateMoneyUnit(unsigned char* imgs, int imgWidth, int imgHeight, int* rowIndexs, int colEleCount, int lines,
        int* result);
 
    
};