浏览代码

1、ConfigManager改名为OptionConfig.

scbc.sat2 5 年之前
父节点
当前提交
9ba69374ef

+ 22 - 23
ssat_sdk/MenuTree3/ConfigManager.py → ssat_sdk/MenuTree3/OptionConfig.py

@@ -13,7 +13,7 @@ g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
 
 # 注意:所有不对外暴露的变量和函数需要私有化,以明确哪些接口和参数是对外的。
 # 这样便于后期维护时,根据对外的变量和函数来做处理。
-class CConfigManager(TConfig, CBaseLog):
+class COptionConfig(TConfig, CBaseLog):
     def __init__(self, menuTreeDir, pathManager):
         self.__pathManager = pathManager
         if self.__pathManager is None:
@@ -49,16 +49,16 @@ class CConfigManager(TConfig, CBaseLog):
         optionName = parent + "WaitTime"
         try:
             waitTime = float(self.get_value("waitTime", optionName))
-        except Exception, e:
+        except Exception:
             waitTime = 1.0
             self.error("获取%s界面的等待界面时间失败,使用默认值1.0s" % str(parent))
         return waitTime
 
     # 获取阀值字典;
-    def getThresholdDict(self, option):
+    def getThresholdDict(self, optionName):
         section = "Threshold"
         thresholdDict = {}
-        value = self.get_value(section, option)
+        value = self.get_value(section, optionName)
         self.info("value:%s,%s" % (value, type(value)))
         if not value:
             return thresholdDict
@@ -90,8 +90,7 @@ class CConfigManager(TConfig, CBaseLog):
         # option聚焦的首配图片路径;
         icon_path = os.path.join(self.__uiTreeDir, "icon\\", cur_parent + "." + cur_level + "_" + optionName + ".png")
         # option聚焦的dir首配图片路径;
-        icon_dir_path = os.path.join(self.__uiTreeDir,
-                                     "icon\\" + cur_parent + "." + cur_level + "_" + optionName + ".dir.png")
+        icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + cur_parent + "." + cur_level + "_" + optionName + ".dir.png")
         # 图片聚焦时的定位参数;
         opc_cfg = self.get_value_dict(cur_level, cur_parent + '.' + optionName)
 
@@ -107,12 +106,8 @@ class CConfigManager(TConfig, CBaseLog):
             if not os.path.exists(icon_path):
                 self.warn("Option(%s)次配图片不存在:%s" % (optionName, icon_path))
                 # 使用顶层配图(first parent)
-                icon_path = os.path.join(self.__uiTreeDir,
-                                         "icon\\" + first_parent + "." + cur_level + "_" + optionName +
-                                         ".png")
-                icon_dir_path = os.path.join(self.__uiTreeDir,
-                                             "icon\\" + first_parent + "." + cur_level + "_" + optionName +
-                                             ".dir.png")
+                icon_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName + ".png")
+                icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName + ".dir.png")
                 opc_cfg = self.get_value_dict(cur_level, first_parent)
                 self.warn("Option(%s)次配图片不存在,尝试使用顶层配图(%s):%s,配置%s" % (optionName, first_parent, icon_path, opc_cfg))
                 # 如果顶层配图不存在,退出;
@@ -139,18 +134,16 @@ class CConfigManager(TConfig, CBaseLog):
     # 获取Option的OCR配置;
     def getOptionOCRConfig(self, optionName):
         ocr_dict = []
+        # 默认的ocr配置;
+        def_orc = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253}, {"lan": "ChinesePRC+English", "type": 10001}]
         paths = self.__pathManager.get_option_paths(optionName)
         # 判断路径节点是否空;
         if paths.__len__() == 0:
-            self.error("当前【%s】的路径节点空" % optionName)
-            ocr_dict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
-                        {"lan": "ChinesePRC+English", "type": 10001}]
+            self.error("当前【%s】的路径节点空,将使用默认的ocr配置%s" % (optionName, def_orc))
         else:
             # 如果状态False,退出;
             if self.status is False:
-                self.warn("配置文件(%s)不存在,%s使用默认的ocr配置" % (self.__configPath, optionName))
-                ocr_dict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
-                            {"lan": "ChinesePRC+English", "type": 10001}]
+                self.warn("配置文件(%s)不存在,%s使用默认的ocr配置%s" % (self.__configPath, optionName, def_orc))
             else:
                 # 读取指定的ocr配置信息;
                 for i in range(g_level.index(paths.__len__() - 1), -1, -1):
@@ -159,23 +152,29 @@ class CConfigManager(TConfig, CBaseLog):
                     cur_level = g_level[i]
                     # 是否有当前option的ocr配置;
                     if self.has_option(cur_level, optionName + '.ocr'):
-                        self.warn("%s使用自身的ocr配置" % optionName)
                         ocr_dict = self.get_dict(self.get_value(cur_level, optionName + '.ocr'))
+                        self.warn("%s使用自身的ocr配置%s" % (optionName, ocr_dict))
                         break
                     # 如果option本身没有配置,获取其父节点的配置;
                     if self.has_option(cur_level, cur_parent + '.ocr'):
-                        self.warn("%s使用父节点%s的ocr配置" % (optionName, cur_parent))
                         ocr_dict = self.get_dict(self.get_value(cur_level, cur_parent + '.ocr'))
+                        self.warn("%s使用父节点%s的ocr配置%s" % (optionName, cur_parent, ocr_dict))
                         break
                     # 如果option父级没有配置,则获取顶层配置(first parent);
                     if self.has_option(cur_level, first_parent + '.ocr'):
-                        self.warn("%s使用顶层节点%s的ocr配置" % (optionName, first_parent))
                         ocr_dict = self.get_dict(self.get_value(cur_level, first_parent + '.ocr'))
+                        self.warn("%s使用顶层节点%s的ocr配置%s" % (optionName, first_parent, ocr_dict))
                         break
                 # end-for
             # end-if
         # end-if
-        self.info("%s使用的ocr配置=%" % (optionName, ocr_dict))
+        if ocr_dict.__len__() == 0:
+            ocr_dict = def_orc
+            self.warn("无有效的ocr配置,将使用默认的ocr配置%s" % def_orc)
+
+        self.info("%s使用的ocr配置=%s" % (optionName, ocr_dict))
+
+        return ocr_dict
 
     # 获取ICON源屏幕的分辨率配置值;
     # 该值用途:由于有些icon是在某些分辨率下截图的,但是同机芯项目可能使用同一套UI,只是分辨率不一样而已。
@@ -187,5 +186,5 @@ class CConfigManager(TConfig, CBaseLog):
 if __name__ == "__main__":
     tData = CTData()
     upath = UITPathManage(tData)
-    opc = CConfigManager(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
+    opc = COptionConfig(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
     print opc.getOptionICONConfig("picture")

+ 7 - 5
ssat_sdk/MenuTree3/OptionFocus.py

@@ -11,7 +11,7 @@ import numpy as np
 import cv2 as cv
 import json
 from BaseLog import CBaseLog
-from ConfigManager import CConfigManager
+from OptionConfig import COptionConfig
 
 # 测试加头文件;
 from TData import CTData
@@ -26,7 +26,7 @@ class COptionFocus(CBaseLog):
             self.error("configManger对象空")
         self.__rgbColor = RGBColor()
         self.__CIE = CIEluvCaculator()
-        self.__feature_detect = FeatureDetect()
+        self.__fd = FeatureDetect()
         # 当前电视机分辨率(通过截图查看图片大小);
         self.__tvResolution = None
         # icon原始分辨率;
@@ -84,9 +84,9 @@ class COptionFocus(CBaseLog):
         icon_bgr = self.__rgbColor.getAvgBGR(icon_img)
 
         # 返回查找结果,失败返回 False, None; 成功返回(焦点的坐标点) True, [l,t,r,b]
-        return self.__feature_detect.findCurrentFoucsByColor(src_pic, [], icon_bgr, icon_cfg['offset'],
-                                                             icon_cfg['minPeri'], icon_cfg['maxPeri'],
-                                                             icon_cfg['minArea'], icon_cfg['maxArea'], morphology)
+        return self.__fd.findCurrentFoucsByColor(src_pic, [], icon_bgr, icon_cfg['offset'],
+                                                 icon_cfg['minPeri'], icon_cfg['maxPeri'],
+                                                 icon_cfg['minArea'], icon_cfg['maxArea'], morphology)
 
     '''
     函数:根据Option的icon配置来查找聚集框;
@@ -173,11 +173,13 @@ class COptionFocus(CBaseLog):
 
         # 记录dir对应的icon等信息, 以备下次使用;
         self.__dirIconRectDict[dir_path] = {"icon_box": focusBox, "width": dir_img.shape[1], "height": dir_img.shape[0]}
+        # 计算起始坐标点;
         x, y = curFocusBox[0] - focusBox[0], curFocusBox[1] - focusBox[1]
 
         # 返回文本框;
         return [x, y, x + dir_img.shape[1], y + dir_img.shape[0]]
 
+
 # end-class
 
 

+ 83 - 0
ssat_sdk/MenuTree3/OptionOCR.py

@@ -0,0 +1,83 @@
+# -*- coding:utf-8 -*-
+import os
+import sys
+import time
+import numpy as np
+import cv2 as cv
+import json
+from BaseLog import CBaseLog
+from OptionConfig import COptionConfig
+from ssat_sdk import OCRConvert, ImageCMP
+
+# 测试加头文件;
+from TData import CTData
+from UIT_PathManage import UITPathManage
+
+
+class COptionOCR(CBaseLog):
+    def __init__(self, optionConfig, pathManager):
+        # COptionConfig对象;
+        self.__optionConfig = optionConfig
+        if self.__optionConfig is None:
+            self.error("configManger对象空")
+        # 路径对象;
+        self.__pathManager = pathManager
+        # 创建OCR对象
+        self.__ocr = OCRConvert()
+        # 图片切割对象
+        self.__imgCMP = ImageCMP()
+        
+    '''
+    函数:获取指定原图中指定的文本区域内的文本内容;
+    参数:
+        src_pid:    原图文件路径;
+        texb_box:   原图中要获取文本内容的区域坐标;
+        ocr_config: 使用何种方式识别文本;   示例:{"lan": "ChinesePRC+English", "type": 4}
+    返回:
+        返回文本内容;
+    '''
+    def getOptionFocusTextByFile(self, src_pic, text_box, ocr_config):
+        src_img = cv.imread(src_pic)
+        if src_img is None:
+            self.error("读取图片失败:%s" % src_pic)
+            return None
+
+        return self.getOptionFocusText(src_img, text_box, ocr_config)
+    
+    '''
+    函数:获取指定原图中指定的文本区域内的文本内容;
+    参数:
+        src_img:    原图图片对象(cv2.imread的结果值);
+        texb_box:   原图中要获取文本内容的区域坐标;
+        ocr_config: 使用何种方式识别文本;   示例:{"lan": "ChinesePRC+English", "type": 4}
+    返回:
+        返回文本内容;
+    '''
+    def getOptionFocusText(self, src_img, text_box, ocr_config):
+        pass
+
+
+    '''
+    函数:识别指定图片文件的文本内容;
+    参数:
+        text_pic:      要识别文本的图片路径;
+        ocr_config:     使用何种方式识别文本;   示例:{"lan": "ChinesePRC+English", "type": 4}
+    返回:
+    '''
+    def getImageText(self, text_pic, ocr_config):
+        text_img = cv.imread(text_pic)
+        if text_img is None:
+            self.error("读取图片失败:%s" % text_pic)
+            return None
+        
+        return self.getImageText(text_img, ocr_config)
+
+    
+# end-class
+
+
+if __name__ == "__main__":
+    tData = CTData()
+    upath = UITPathManage(tData)
+    opcfg = CoptionConfig(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
+    opfocus = COptionOCR(opcfg, upath)

+ 3 - 1
ssat_sdk/MenuTree3/TData.py

@@ -1,6 +1,8 @@
 # -*- coding:utf-8 -*-
 import os,sys,time
-from ssat_sdk.MenuTree3.TExcelParser import CExcelParser
+#from ssat_sdk.MenuTree3.TExcelParser import CExcelParser
+# 测试路径;
+from TExcelParser import CExcelParser
 from ssat_sdk import getMenuTree3SelectedProjectCfgPath, getMenuTree3SelectedPExcelPath
 from UIT_tree import UITTree
 from UIT_FileManage import UITFileManage

+ 2 - 2
ssat_sdk/MenuTree3/UIT_PathManage.py

@@ -71,8 +71,8 @@ class UITPathManage():
                                     "move_key": self.pathParams.paths[level][parent][TreeConst.Option_MoveKey],
                                     "enter_key": self.pathParams.paths[level][parent][TreeConst.Option_EnterKey],
                                     "others": self.pathParams.paths[level][parent][TreeConst.Option_Others],
-                                    "option": item["option"],
-                                    "option_for_ocr": item["option_for_ocr"].split(';'),
+                                    "option": item[TreeConst.Option_Name],
+                                    "option_for_ocr": item[TreeConst.Option_ForOCR].split(';'),
                                     "option_move_key": item[TreeConst.Option_MoveKey],
                                     "option_enter_key": item[TreeConst.Option_EnterKey],
                                     "option_others": item[TreeConst.Option_Others]

+ 1 - 0
ssat_sdk/MenuTree3/UIT_tree.py

@@ -15,6 +15,7 @@ def parseMoveKey(keyStr):
     return strToList(keyStr,";")
 
 class CPathParams():
+    cls = "CPathParams"
     def __init__(self):
         self.paths = OrderedDict()