MCPcopy Index your code
hub / github.com/pyload/pyload / get_bg

Method get_bg

module/plugins/captcha/LinksaveIn.py:56–92  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

54 self.result_captcha = ""
55
56 def get_bg(self):
57 stat = {}
58 cstat = {}
59 img = self.img.convert("P")
60 for bgpath in glob.glob(self.data_dir + "bg/*.gif"):
61 stat[bgpath] = 0
62 bg = Image.open(bgpath)
63
64 bglut = bg.resize((256, 1))
65 bglut.putdata(range(256))
66 bglut = list(bglut.convert("RGB").getdata())
67
68 lut = img.resize((256, 1))
69 lut.putdata(range(256))
70 lut = list(lut.convert("RGB").getdata())
71
72 bgpix = bg.load()
73 pix = img.load()
74 for x in range(bg.size[0]):
75 for y in range(bg.size[1]):
76 rgb_bg = bglut[bgpix[x, y]]
77 rgb_c = lut[pix[x, y]]
78 try:
79 cstat[rgb_c] += 1
80
81 except Exception:
82 cstat[rgb_c] = 1
83
84 if rgb_bg == rgb_c:
85 stat[bgpath] += 1
86 max_p = 0
87 bg = ""
88 for bgpath, value in stat.items():
89 if max_p < value:
90 bg = bgpath
91 max_p = value
92 return bg
93
94 def substract_bg(self, bgpath):
95 bg = Image.open(bgpath)

Callers 1

recognizeMethod · 0.95

Calls 3

itemsMethod · 0.80
openMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected