MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / getCount

Function getCount

tools/ImageCropper/colormatcher.py:38–68  ·  view source on GitHub ↗

获取匹配成功的数量 Args: img: 图片 lower: 颜色下限值 upper: 颜色上限值 connected: bool 是否是相连的点才会被计数 method: int = -1 颜色匹配方式。即 cv::ColorConversionCodes。可选,默认 4 (RGB)。 常用值:4 (RGB, 3 通道), 40 (HSV, 3

(img, lower, upper, connected: bool, method: int = -1)

Source from the content-addressed store, hash-verified

36 return ret
37
38def getCount(img, lower, upper, connected: bool, method: int = -1) -> int:
39 '''
40 获取匹配成功的数量
41
42 Args:
43 img:
44 图片
45 lower:
46 颜色下限值
47 upper:
48 颜色上限值
49 connected: bool
50 是否是相连的点才会被计数
51 method: int = -1
52 颜色匹配方式。即 cv::ColorConversionCodes。可选,默认 4 (RGB)。
53 常用值:4 (RGB, 3 通道), 40 (HSV, 3 通道), 6 (GRAY, 1 通道)。
54 默认不进行转换。
55 Return:
56 int
57 '''
58 # https://github.com/MaaXYZ/MaaFramework/blob/main/source/MaaFramework/Vision/ColorMatcher.cpp
59 # ColorMatcher::color_match
60 if method >= 0:
61 img = cv2.cvtColor(img, method)
62 bin = cv2.inRange(img, np.array(lower, img.dtype), np.array(upper, img.dtype))
63 # __show(img)
64 # __show(bin)
65 if connected:
66 return __count_non_zero_with_connected(bin)
67 else:
68 return cv2.countNonZero(bin)
69
70def __count_non_zero_with_connected(bin):
71 number, labels, stats, centroids = cv2.connectedComponentsWithStats(bin, connectivity=8, ltype=cv2.CV_16U)

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected