/**************************************************************************** ** File name : HTOpencvImg.h ** Description : define Opencv function ** Create date : 2018.09.01 ** Auther by : Liuyx ** Version info : V1.0.01 ** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd ** Update record: ** DATE AUTHER DESC ** ------------------------------------------------------------------------- ** 2018.09.01 Liuyx first build ****************************************************************************/ #ifndef __HT_OPENCV_IMG_H #define __HT_OPENCV_IMG_H #pragma warning(disable: 4819) #include #include "HTGlobal.h" //#include "opencv/cv.h" #include #include #include #include #include #include #include //#define _HT_OPENCV_TEST_ENV // 测试环境,产生随机数作为分析表的数据 #pragma pack (push ,1) //OpencvDirTraverse.cpp : Defines the entry point for the console application. #ifdef _WIN32 #ifdef _DEBUG #pragma comment(lib,"opencv_world3416d.lib") #else #pragma comment(lib,"opencv_world3416.lib") #endif //#pragma comment(lib,"opencv_ts300d.lib") #endif using namespace std; using namespace cv; #if (defined _WIN32) || (defined _WIN64) static const char HT_CONFIMG_FILE[] = "..\\etc\\htimg-win.conf"; #else static const char HT_CONFIMG_FILE[] = "../etc/htimg.conf"; #endif #define eps 0.0000000001 #define PI acos(-1.0) //#define MAX_FILE_SIZE 8294454 // 图片文件大小(字节) //#define MAX_FILE_SIZE 177400 //#define _IM_SHOW // 显示图片 //#define _IMG_MIDILL_SAVE // 保存最终变换图片 typedef struct _CONF_IMG { //[CAMERA_01] int seqno; // 序列号,001-999之间 unsigned char eqm_type[2]; // 主设备类型, T-主变 G-GIS B-避雷器 unsigned char site_id[DEF_EQM_CODE_SIZE]; // 站点ID unsigned char eqm_code[DEF_EQM_CODE_SIZE]; // 主设备编码 unsigned char sys_code[DEF_EQM_CODE_SIZE]; // 主设备系统编码 unsigned char table_type[32]; // 仪表类型名称 unsigned char name[32]; //# 拍摄对象名称,变压器放电拍照设备 unsigned char sersorid[DEF_EQM_CODE_SIZE]; //# 设备的sersor_id, 与数据库一一对应 unsigned int base_angle; //# 仪表基准度数, 180° 或360° unsigned char meter_type; //# 仪表的数据单位类型, 0:电流 1 : 压力 2 : 容量(油位) 3: 温度 unsigned char meter_units; //# 对应于meter_type的单位 unsigned char direct_Clockwise;// 仪表读数的方向, 正时针 = 1 反时针 = 0 double dInitVal; // 初始值 unsigned int max_pointer_len; //# 最大指针长度(mm), 20mm~200mm, 默认:100 unsigned char img_path[MAX_PATH]; // 图片文件路径及类型: ../img01/*.* or ../img01/*.jpg ... unsigned char img_bak[MAX_PATH]; // 图片文件备份路径../img01/bak ... bool is_replace; //true: 覆盖原文件,不保留原文件,文件名不变;false: 保留原文件,并将截图文件命名为 xxx_cut.xxx //# 截图区域配置 int s_height; //# 起始行 / 高度 / Y / H / rows int e_height; //# 结束行 / 高度 / Y / H / rows int s_width; //# 起始列 / 宽度 / X / W / cols int e_width; //# 结束列 / 宽度 / X / W / cols int img_min_size; // 图片文件最小字节数 }ST_OPENCV_CONF; typedef struct _YB_TYPE { int len; // 线长度 double du; // 角度 double val; // 对应的值 }ST_YB_TYPE; static const ST_YB_TYPE g_YB_3EX5050[] = { { 156, 139.00, 0 }, { 156, 127.00, 1 }, { 156, 116.00, 2 }, { 156, 105.00, 3 }, { 156, 90.00, 10 }, { 156, 75.00, 20 }, { 156, 52.00, 30 }, { -1, 0, 0 } }; static const ST_YB_TYPE g_YB_JSY10[] = { { 306, 90.00, 0 }, { 306, 54.00, 1 }, { 306, 18.00, 2 }, { 306, 342.00, 3 }, { 306, 306.00, 4 }, { 306, 270.00, 5 }, { 306, 234.00, 6 }, { 306, 198.00, 7 }, { 306, 162.00, 8 }, { 306, 126.00, 9 }, { -1, 0, 0 } }; static const ST_YB_TYPE g_YB_YZFTH[] = { { 220, 45.00, 10.00 }, { 220, 47.70, 9.90 }, { 220, 50.40, 9.80 }, { 220, 53.10, 9.70 }, { 220, 55.80, 9.60 }, { 220, 58.50, 9.50 }, { 220, 61.20, 9.40 }, { 220, 63.90, 9.30 }, { 220, 66.60, 9.20 }, { 220, 69.30, 9.10 }, { 220, 72.00, 9.00 }, { 220, 74.70, 8.90 }, { 220, 77.40, 8.80 }, { 220, 80.10, 8.70 }, { 220, 82.80, 8.60 }, { 220, 85.50, 8.50 }, { 220, 88.20, 8.40 }, { 220, 90.90, 8.30 }, { 220, 93.60, 8.20 }, { 220, 96.30, 8.10 }, { 220, 99.00, 8.00 }, { 220, 101.70, 7.90 }, { 220, 104.40, 7.80 }, { 220, 107.10, 7.70 }, { 220, 109.80, 7.60 }, { 220, 112.50, 7.50 }, { 220, 115.20, 7.40 }, { 220, 117.90, 7.30 }, { 220, 120.60, 7.20 }, { 220, 123.30, 7.10 }, { 220, 126.00, 7.00 }, { 220, 128.70, 6.90 }, { 220, 131.40, 6.80 }, { 220, 134.10, 6.70 }, { 220, 136.80, 6.60 }, { 220, 139.50, 6.50 }, { 220, 142.20, 6.40 }, { 220, 144.90, 6.30 }, { 220, 147.60, 6.20 }, { 220, 150.30, 6.10 }, { 220, 153.00, 6.00 }, { 220, 155.70, 5.90 }, { 220, 158.40, 5.80 }, { 220, 161.10, 5.70 }, { 220, 163.80, 5.60 }, { 220, 166.50, 5.50 }, { 220, 169.20, 5.40 }, { 220, 171.90, 5.30 }, { 220, 174.60, 5.20 }, { 220, 177.30, 5.10 }, { 220, 180.00, 5.00 }, { 220, 182.70, 4.90 }, { 220, 185.40, 4.80 }, { 220, 188.10, 4.70 }, { 220, 190.80, 4.60 }, { 220, 193.50, 4.50 }, { 220, 196.20, 4.40 }, { 220, 198.90, 4.30 }, { 220, 201.60, 4.20 }, { 220, 204.30, 4.10 }, { 220, 207.00, 4.00 }, { 220, 209.70, 3.90 }, { 220, 212.40, 3.80 }, { 220, 215.10, 3.70 }, { 220, 217.80, 3.60 }, { 220, 220.50, 3.50 }, { 220, 223.20, 3.40 }, { 220, 225.90, 3.30 }, { 220, 228.60, 3.20 }, { 220, 231.30, 3.10 }, { 220, 234.00, 3.00 }, { 220, 236.70, 2.90 }, { 220, 239.40, 2.80 }, { 220, 242.10, 2.70 }, { 220, 244.80, 2.60 }, { 220, 247.50, 2.50 }, { 220, 250.20, 2.40 }, { 220, 252.90, 2.30 }, { 220, 255.60, 2.20 }, { 220, 258.30, 2.10 }, { 220, 261.00, 2.00 }, { 220, 263.70, 1.90 }, { 220, 266.40, 1.80 }, { 220, 269.10, 1.70 }, { 220, 271.80, 1.60 }, { 220, 274.50, 1.50 }, { 220, 277.20, 1.40 }, { 220, 279.90, 1.30 }, { 220, 282.60, 1.20 }, { 220, 285.30, 1.10 }, { 220, 288.00, 1.00 }, { 220, 290.70, 0.90 }, { 220, 293.40, 0.80 }, { 220, 296.10, 0.70 }, { 220, 298.80, 0.60 }, { 220, 301.50, 0.50 }, { 220, 304.20, 0.40 }, { 220, 306.90, 0.30 }, { 220, 309.60, 0.20 }, { 220, 312.30, 0.10 }, { 220, 315.00, 0.00 }, { -1, 0, 0 } }; // 150摄氏度的油温表读数 static const ST_YB_TYPE g_YB_WSS150[] = { { 183, 225.00, 0.00 }, { 183, 219.60, 3.00 }, { 183, 214.20, 6.00 }, { 183, 208.80, 9.00 }, { 183, 203.40, 12.00 }, { 183, 198.00, 15.00 }, { 183, 192.60, 18.00 }, { 183, 187.20, 21.00 }, { 183, 181.80, 24.00 }, { 183, 176.40, 27.00 }, { 183, 171.00, 30.00 }, { 183, 165.60, 33.00 }, { 183, 160.20, 36.00 }, { 183, 154.80, 39.00 }, { 183, 149.40, 42.00 }, { 183, 144.00, 45.00 }, { 183, 138.60, 48.00 }, { 183, 133.20, 51.00 }, { 183, 127.80, 54.00 }, { 183, 122.40, 57.00 }, { 183, 117.00, 60.00 }, { 183, 111.60, 63.00 }, { 183, 106.20, 66.00 }, { 183, 100.80, 69.00 }, { 183, 95.40, 72.00 }, { 183, 90.00, 75.00 }, { 183, 84.60, 78.00 }, { 183, 79.20, 81.00 }, { 183, 73.80, 84.00 }, { 183, 68.40, 87.00 }, { 183, 63.00, 90.00 }, { 183, 57.60, 93.00 }, { 183, 52.20, 96.00 }, { 183, 46.80, 99.00 }, { 183, 41.40, 102.00 }, { 183, 36.00, 105.00 }, { 183, 30.60, 108.00 }, { 183, 25.20, 111.00 }, { 183, 19.80, 114.00 }, { 183, 14.40, 117.00 }, { 183, 9.00, 120.00 }, { 183, 3.60, 123.00 }, { 183, 358.20, 126.00 }, { 183, 325.80, 129.00 }, { 183, 347.40, 132.00 }, { 183, 342.00, 135.00 }, { 183, 336.60, 138.00 }, { 183, 331.20, 141.00 }, { 183, 325.80, 144.00 }, { 183, 320.40, 147.00 }, { 183, 315.00, 150.00 }, { -1, 0, 0 } }; // 100摄氏度的温度表读数 static const ST_YB_TYPE g_YB_WSS100[] = { { 183, 225.00, 0.00 }, { 183, 219.60, 2.00 }, { 183, 214.20, 4.00 }, { 183, 208.80, 6.00 }, { 183, 203.40, 8.00 }, { 183, 198.00, 10.00 }, { 183, 192.60, 12.00 }, { 183, 187.20, 14.00 }, { 183, 181.80, 16.00 }, { 183, 176.40, 18.00 }, { 183, 171.00, 20.00 }, { 183, 165.60, 22.00 }, { 183, 160.20, 24.00 }, { 183, 154.80, 26.00 }, { 183, 149.40, 28.00 }, { 183, 144.00, 30.00 }, { 183, 138.60, 32.00 }, { 183, 133.20, 34.00 }, { 183, 127.80, 36.00 }, { 183, 122.40, 38.00 }, { 183, 117.00, 40.00 }, { 183, 111.60, 42.00 }, { 183, 106.20, 44.00 }, { 183, 100.80, 46.00 }, { 183, 95.40, 48.00 }, { 183, 90.00, 50.00 }, { 183, 84.60, 52.00 }, { 183, 79.20, 54.00 }, { 183, 73.80, 56.00 }, { 183, 68.40, 58.00 }, { 183, 63.00, 60.00 }, { 183, 57.60, 62.00 }, { 183, 52.20, 64.00 }, { 183, 46.80, 66.00 }, { 183, 41.40, 68.00 }, { 183, 36.00, 70.00 }, { 183, 30.60, 72.00 }, { 183, 25.20, 74.00 }, { 183, 19.80, 76.00 }, { 183, 14.40, 78.00 }, { 183, 9.00, 80.00 }, { 183, 3.60, 82.00 }, { 183, 361.80, 84.00 }, { 183, 356.40, 86.00 }, { 183, 351.00, 88.00 }, { 183, 345.60, 90.00 }, { 183, 340.20, 92.00 }, { 183, 334.80, 94.00 }, { 183, 329.40, 96.00 }, { 183, 324.00, 98.00 }, { 180, 318.60, 100.00 }, { -1, 0, 0 } }; // 1.6MPa压力表读数 static const ST_YB_TYPE g_YB_OCR17NI12MO2_16[] = { { 183, 225.00, 0.00 }, { 183, 221.63, 0.02 }, { 183, 218.25, 0.04 }, { 183, 214.88, 0.06 }, { 183, 211.50, 0.08 }, { 183, 208.13, 0.10 }, { 183, 204.75, 0.12 }, { 183, 201.38, 0.14 }, { 183, 198.00, 0.16 }, { 183, 194.63, 0.18 }, { 183, 191.25, 0.20 }, { 183, 187.88, 0.22 }, { 183, 184.50, 0.24 }, { 183, 181.13, 0.26 }, { 183, 177.75, 0.28 }, { 183, 174.38, 0.30 }, { 183, 171.00, 0.32 }, { 183, 167.63, 0.34 }, { 183, 164.25, 0.36 }, { 183, 160.88, 0.38 }, { 183, 157.50, 0.40 }, { 183, 154.13, 0.42 }, { 183, 150.75, 0.44 }, { 183, 147.38, 0.46 }, { 183, 144.00, 0.48 }, // 144.74 - 0.5 { 183, 140.63, 0.50 }, { 183, 137.25, 0.52 }, { 183, 133.88, 0.54 }, { 183, 130.50, 0.56 }, { 183, 127.13, 0.58 }, { 183, 123.75, 0.60 }, { 183, 120.38, 0.62 }, { 183, 117.00, 0.64 }, { 183, 113.63, 0.66 }, { 183, 110.25, 0.68 }, { 183, 106.88, 0.70 }, { 183, 103.50, 0.72 }, { 183, 100.13, 0.74 }, { 183, 96.75, 0.76 }, { 183, 93.38, 0.78 }, { 183, 90.00, 0.80 }, { 183, 86.63, 0.82 }, { 183, 83.25, 0.84 }, { 183, 79.88, 0.86 }, { 183, 76.50, 0.88 }, { 183, 73.13, 0.90 }, { 183, 69.75, 0.92 }, { 183, 66.38, 0.94 }, { 183, 63.00, 0.96 }, { 183, 59.63, 0.98 }, { 183, 56.25, 1.00 }, { 183, 52.88, 1.02 }, { 183, 49.50, 1.04 }, { 183, 46.13, 1.06 }, { 183, 42.75, 1.08 }, { 183, 39.38, 1.10 }, { 183, 36.00, 1.12 }, { 183, 32.63, 1.14 }, { 183, 29.25, 1.16 }, { 183, 25.88, 1.18 }, { 183, 22.50, 1.20 }, { 183, 19.13, 1.22 }, { 183, 15.75, 1.24 }, { 183, 12.38, 1.26 }, { 183, 9.00, 1.28 }, { 183, 5.63, 1.30 }, { 183, 2.25, 1.32 }, { 183, 361.13, 1.34 }, { 183, 357.75, 1.36 }, { 183, 354.38, 1.38 }, { 183, 351.00, 1.40 }, { 183, 347.63, 1.42 }, { 183, 344.25, 1.44 }, { 183, 340.88, 1.46 }, { 183, 337.50, 1.48 }, { 183, 334.13, 1.50 }, { 183, 330.75, 1.52 }, { 183, 327.38, 1.54 }, { 183, 324.00, 1.56 }, { 183, 320.63, 1.58 }, { 180, 317.25, 1.60 }, { -1, 0, 0 } }; // 2.5MPa压力表读数 static const ST_YB_TYPE g_YB_OCR17NI12MO2_25[] = { { 183, 225.00, 0.00 }, { 183, 219.60, 0.05 }, { 183, 214.20, 0.10 }, { 183, 208.80, 0.15 }, { 183, 203.40, 0.20 }, { 183, 198.00, 0.25 }, { 183, 192.60, 0.30 }, { 183, 187.20, 0.35 }, { 183, 181.80, 0.40 }, { 183, 176.40, 0.45 }, { 183, 171.00, 0.50 }, { 183, 165.60, 0.55 }, { 183, 160.20, 0.60 }, { 183, 154.80, 0.65 }, { 183, 149.40, 0.70 }, { 183, 144.00, 0.75 }, { 183, 138.60, 0.80 }, { 183, 133.20, 0.85 }, { 183, 127.80, 0.90 }, { 183, 122.40, 0.95 }, { 183, 117.00, 1.00 }, { 183, 111.60, 1.05 }, { 183, 106.20, 1.10 }, { 183, 100.80, 1.15 }, { 183, 95.40, 1.20 }, { 183, 90.00, 1.25 }, { 183, 84.60, 1.30 }, { 183, 79.20, 1.35 }, { 183, 73.80, 1.40 }, { 183, 68.40, 1.45 }, { 183, 63.00, 1.50 }, { 183, 57.60, 1.55 }, { 183, 52.20, 1.60 }, { 183, 46.80, 1.65 }, { 183, 41.40, 1.70 }, { 183, 36.00, 1.75 }, { 183, 30.60, 1.80 }, { 183, 25.20, 1.85 }, { 183, 19.80, 1.90 }, { 183, 14.40, 1.95 }, { 183, 9.00, 2.00 }, { 183, 3.60, 2.05 }, { 183, 361.80, 2.10 }, { 183, 356.40, 2.15 }, { 183, 351.00, 2.20 }, { 183, 345.60, 2.25 }, { 183, 340.20, 2.30 }, { 183, 334.80, 2.35 }, { 183, 329.40, 2.40 }, { 183, 324.00, 2.45 }, { 183, 318.60, 2.50 }, { -1, 0, 0 } }; #pragma pack (pop) //181 - 0 = 181 //530 - //495 //224 //135 //123 //92 //自定义直线 class MyLine { public: int id; //编号 int k; //倾斜角[0-360) int l; //长度 public: MyLine(int ID = 0, int K = 0, int L = 0){ id = ID, k = K, l = L; } //构造函数 bool operator<(const MyLine &A) { return k < A.k; } //重定义小于号 void print(){ printf("id: %3d k: %3d° l: %3d\n", id, k, l); }//输出函数 }; //显示图片 void showImg(const char *title, Mat &img); //点到线段的距离 double DistancetoSegment(Point P, Point A, Point B); //向量模长 double Length(Point A); double gtest(double du, double base, int linelen); // for test // 读取仪表指针数值 //double dReadPointValue(const char *tbale_type, const char *jpg_file, double base); double dReadPointValue_JSY10(ST_OPENCV_CONF *stConf, const char *jpg_file); double dReadPointValue_3EX5050(ST_OPENCV_CONF *stConf, const char *jpg_file); //double dReadPointValue_YZF250TH_T4(ST_OPENCV_CONF *stConf, const char *jpg_file); double dReadPointValues(ST_OPENCV_CONF *stConf, const char *jpg_file); //double dGetReadValueOfYZFTH(double du, double base, int linelen); /* pPath : path, eg: /usr/local/img/*.jpg : "D:\\Photo and Video\\destop1\\*.jpg"; */ int iGetImgFileList(const char *pPath, std::vector & image_files); // 播放视频流 int showRtspVideoStream(const char* rtsp_url); int showRtspVideoStreams(const char *rtsp_url); // 截取图片指定区域并保存 // isReplace = true: 覆盖原文件,不保留原文件,文件名不变 // = false: 保留原文件,并将截图文件命名为 xxx_cut.xxx //int vCutImageSave(char* path_filename, int shigh, int ehigh, int swidth, int ewidth, bool isReplace); int vCutImageSave(ST_OPENCV_CONF *stConf, char* path_filename); // 仪表盘的单位转换 double dChangeUnits(unsigned char *sersorid, double inVal); // 图片识别处理线程 void* thread_opencv_proc(void * arg); bool bBakFilename(char *filename, char *pBakPath); double dReadPointValue_Wss411_150_T1(ST_OPENCV_CONF *stConf, const char *jpg_file); #endif // !__HT_OPENCV_IMG_H_