<jupyter_start><jupyter_text>**注：以下是试验**<jupyter_code>imgs = extract_text_img(img)
if len(imgs) == 1:
    plt.subplot(1, 2, 1)
    plt.imshow(imgs[0], cmap='gray')
else:
    plt.subplot(1, 2, 1)
    plt.imshow(imgs[0], cmap='gray')
    plt.subplot(1, 2, 2)
    plt.imshow(imgs[1], cmap='gray')

import hashlib
m = hashlib.md5()
for val in imgs[0]:
    m.update(val)
m.hexdigest()
def extract_text_img(img):
    text_img = img[:29, 117:250]
    text_img = cv2.cvtColor(text_img, cv2.COLOR_BGR2GRAY)
    
    text_img2 = cv2.GaussianBlur(text_img, (3,3), 1)
    sobelY = np.array([
        [-1, 0, 1],
        [-2, 0, 2],
        [-1, 0, 1]
    ])
    edges = cv2.filter2D(text_img2, -1, sobelY)
    _, thres = cv2.threshold(edges, 0, 1, cv2.THRESH_OTSU)
    
    col_sum = np.sum(thres, axis=0)
    divides = np.argwhere(col_sum > 27).squeeze()
    imgs = []
    
    if len(divides) < 2:
        _, thres = cv2.threshold(text_img, 0, 1, cv2.THRESH_OTSU)
        col_sum = np.sum(thres, axis=0)
        divides = np.argwhere(col_sum < 26)
        right = np.max(divides) + 12
        imgs.append(text_img[:, :right])
    else:
        last_num = 2
        cnt = 0
        sums = 0
        ans = []
        for num in divides:
            if num == last_num + 1:
                sums += num
                cnt += 1
            else:
                if cnt > 0:
                    ans.append(int(round(sums / cnt)))
                sums = num
                cnt = 1
            last_num = num
        ans.append(int(round(sums / cnt)))
        
        imgs.append(text_img[:, :ans[0]].copy())
        imgs.append(text_img[:, ans[0]:ans[1]].copy())
        # assert len(ans) == 2
    return imgs
text_img = img[:29, 117:230]
text_img = cv2.cvtColor(text_img, cv2.COLOR_BGR2GRAY)
plt.imshow(text_img, cmap='gray')
text_img2 = cv2.GaussianBlur(text_img, (3,3), 1)
sobelY = np.array([
    [-1, 0, 1],
    [-2, 0, 2],
    [-1, 0, 1]
])
edges = cv2.filter2D(text_img2, -1, sobelY)
plt.imshow(edges, cmap='gray')
_, thres = cv2.threshold(edges, 0, 1, cv2.THRESH_OTSU)
plt.imshow(thres, cmap='gray')
col_sum = np.sum(thres, axis=0)
divides = np.argwhere(col_sum > 27).squeeze()
print(divides)
last_num = 2
cnt = 0
sums = 0
ans = []
for num in divides:
    if num == last_num + 1:
        sums += num
        cnt += 1
    else:
        if cnt > 0:
            ans.append(int(round(sums / cnt)))
        sums = num
        cnt = 1
    last_num = num
ans.append(int(round(sums / cnt)))

# assert len(ans) == 2
print(ans)
img1 = text_img[:, :ans[0]].copy()
img2 = text_img[:, ans[0]:ans[1]].copy()

plt.subplot(1,2,1)
plt.imshow(img1, cmap='gray')

plt.subplot(1,2,2)
plt.imshow(img2, cmap='gray')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16789396170839468, 'fraction_numerical': 0.047496318114874814, 'mean_word_length': 2.3337423312883434, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '190033', 'license': 'Apache-2.0', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1139, 'n_words': 224, 'path': 'Captcha-Interaction-Test.ipynb', 'repo_name': 'SpiritedAwayCN/Cracking-12306', 'size': '2716'}