|
@@ -264,7 +264,61 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
let maxWidth = min(rWidth, cWidth) - 1
|
|
|
let maxHeight = min(rHeight, cHeight) - 1
|
|
|
|
|
|
+ // check background color
|
|
|
+ // 挑选图片 对角斜线 上的相素进行识别
|
|
|
+ var markInfo = NSMutableDictionary.init()
|
|
|
+ for w in 0...maxWidth {
|
|
|
+ let x = Int(w)
|
|
|
+ for mark in 0...1 {
|
|
|
+ let color = checkImageRep.colorAt(x: min(x, cWidth-1), y: min(mark == 0 ? x : (maxWidth - x), (cHeight-1))) as! NSColor
|
|
|
+
|
|
|
+ let r = Int(color.redComponent*255)
|
|
|
+ let g = Int(color.greenComponent*255)
|
|
|
+ let b = Int(color.blueComponent*255)
|
|
|
+
|
|
|
+ let key = String("\(r)-\(g)-\(b)")
|
|
|
+
|
|
|
+ if (markInfo[key] != nil) {
|
|
|
+ let count = (markInfo[key] as? NSNumber)!.intValue ?? 0
|
|
|
+
|
|
|
+ markInfo[key] = NSNumber.init(value: count + 1)
|
|
|
+ }else {
|
|
|
+ markInfo[key] = NSNumber.init(value: 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var maxCount = Int(0);
|
|
|
+ var bgColorString : String? = nil
|
|
|
+ for key in markInfo.allKeys {
|
|
|
+ let count = (markInfo[key] as? NSNumber)!.intValue ?? 0
|
|
|
+
|
|
|
+ if count > maxCount {
|
|
|
+ maxCount = count
|
|
|
+ bgColorString = key as! String
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var bgColor : NSColor? = nil
|
|
|
+ if bgColorString != nil {
|
|
|
+ let coms = NSString(string: bgColorString!).components(separatedBy: "-")
|
|
|
+
|
|
|
+ let r = NSString(string: coms[0]).intValue
|
|
|
+ let g = NSString(string: coms[1]).intValue
|
|
|
+ let b = NSString(string: coms[2]).intValue
|
|
|
+ bgColor = NSColor(red: CGFloat(CGFloat(r)/255.0),
|
|
|
+ green: CGFloat(CGFloat(g)/255.0),
|
|
|
+ blue: CGFloat(CGFloat(b)/255.0),
|
|
|
+ alpha: 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ if nil != bgColor {
|
|
|
+ NSLog(String("识别到背景色\(bgColor)"))
|
|
|
+ }
|
|
|
+
|
|
|
+ // Compare
|
|
|
var equalCount = 0 as Double
|
|
|
+ var bgCount = 0 as Double
|
|
|
for w in 0...maxWidth {
|
|
|
let x = Int(w)
|
|
|
|
|
@@ -276,11 +330,16 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
|
|
|
if (cColor.isEqual(to: rColor)) {
|
|
|
equalCount = equalCount + 1
|
|
|
+
|
|
|
+ if bgColor != nil &&
|
|
|
+ cColor.isEqual(to: bgColor) {
|
|
|
+ bgCount += 1
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return Double(equalCount/(Double(cWidth) * Double(cHeight)) * 100.0)
|
|
|
+ return Double(max(equalCount-bgCount, 1)/(max(Double(cWidth) * Double(cHeight)-bgCount, 1)) * 100.0)
|
|
|
}
|
|
|
|
|
|
// Update Refrence image
|