mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-03-17 00:40:59 +08:00
i18n: translate all Chinese comments, docstrings, and logger messages to English
Comprehensive translation of Chinese text to English across the entire codebase: - api/: FastAPI server documentation and logger messages - cache/: Cache abstraction layer comments and docstrings - database/: Database models and MongoDB store documentation - media_platform/: All platform crawlers (Bilibili, Douyin, Kuaishou, Tieba, Weibo, Xiaohongshu, Zhihu) - model/: Data model documentation - proxy/: Proxy pool and provider documentation - store/: Data storage layer comments - tools/: Utility functions and browser automation - test/: Test file documentation Preserved: Chinese disclaimer header (lines 10-18) for legal compliance 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author : relakkes@gmail.com
|
||||
# @Time : 2023/12/2 12:55
|
||||
# @Desc : 滑块相关的工具包
|
||||
# @Desc : Slider verification utility package
|
||||
import os
|
||||
from typing import List
|
||||
from urllib.parse import urlparse
|
||||
@@ -38,8 +38,8 @@ class Slide:
|
||||
"""
|
||||
def __init__(self, gap, bg, gap_size=None, bg_size=None, out=None):
|
||||
"""
|
||||
:param gap: 缺口图片链接或者url
|
||||
:param bg: 带缺口的图片链接或者url
|
||||
:param gap: Gap image path or url
|
||||
:param bg: Background image with gap path or url
|
||||
"""
|
||||
self.img_dir = os.path.join(os.getcwd(), 'temp_image')
|
||||
if not os.path.exists(self.img_dir):
|
||||
@@ -76,13 +76,13 @@ class Slide:
|
||||
cv2.imwrite(img_path, image)
|
||||
return img_path
|
||||
else:
|
||||
raise Exception(f"保存{img_type}图片失败")
|
||||
raise Exception(f"Failed to save {img_type} image")
|
||||
else:
|
||||
return img
|
||||
|
||||
@staticmethod
|
||||
def clear_white(img):
|
||||
"""清除图片的空白区域,这里主要清除滑块的空白"""
|
||||
"""Clear whitespace from image, mainly clearing slider whitespace"""
|
||||
img = cv2.imread(img)
|
||||
rows, cols, channel = img.shape
|
||||
min_x = 255
|
||||
@@ -108,16 +108,16 @@ class Slide:
|
||||
def template_match(self, tpl, target):
|
||||
th, tw = tpl.shape[:2]
|
||||
result = cv2.matchTemplate(target, tpl, cv2.TM_CCOEFF_NORMED)
|
||||
# 寻找矩阵(一维数组当作向量,用Mat定义) 中最小值和最大值的位置
|
||||
# Find min and max value positions in matrix
|
||||
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
|
||||
tl = max_loc
|
||||
br = (tl[0] + tw, tl[1] + th)
|
||||
# 绘制矩形边框,将匹配区域标注出来
|
||||
# target:目标图像
|
||||
# tl:矩形定点
|
||||
# br:矩形的宽高
|
||||
# (0,0,255):矩形边框颜色
|
||||
# 1:矩形边框大小
|
||||
# Draw rectangle border to mark the matched area
|
||||
# target: target image
|
||||
# tl: rectangle top-left corner
|
||||
# br: rectangle width and height
|
||||
# (0,0,255): rectangle border color
|
||||
# 1: rectangle border size
|
||||
cv2.rectangle(target, tl, br, (0, 0, 255), 2)
|
||||
cv2.imwrite(self.out, target)
|
||||
return tl[0]
|
||||
@@ -138,39 +138,39 @@ class Slide:
|
||||
slide_pic = cv2.cvtColor(slide, cv2.COLOR_GRAY2RGB)
|
||||
back_pic = cv2.cvtColor(back, cv2.COLOR_GRAY2RGB)
|
||||
x = self.template_match(slide_pic, back_pic)
|
||||
# 输出横坐标, 即 滑块在图片上的位置
|
||||
# Output x-coordinate, i.e., slider position on image
|
||||
return x
|
||||
|
||||
|
||||
def get_track_simple(distance) -> List[int]:
|
||||
# 有的检测移动速度的 如果匀速移动会被识别出来,来个简单点的 渐进
|
||||
# distance为传入的总距离
|
||||
# 移动轨迹
|
||||
# Some detection checks movement speed - constant speed will be detected, so use gradual acceleration
|
||||
# distance is the total distance to move
|
||||
# Movement track
|
||||
track: List[int] = []
|
||||
# 当前位移
|
||||
# Current displacement
|
||||
current = 0
|
||||
# 减速阈值
|
||||
# Deceleration threshold
|
||||
mid = distance * 4 / 5
|
||||
# 计算间隔
|
||||
# Time interval
|
||||
t = 0.2
|
||||
# 初速度
|
||||
# Initial velocity
|
||||
v = 1
|
||||
|
||||
while current < distance:
|
||||
if current < mid:
|
||||
# 加速度为2
|
||||
# Acceleration = 4
|
||||
a = 4
|
||||
else:
|
||||
# 加速度为-2
|
||||
# Acceleration = -3
|
||||
a = -3
|
||||
v0 = v
|
||||
# 当前速度
|
||||
# Current velocity
|
||||
v = v0 + a * t # type: ignore
|
||||
# 移动距离
|
||||
# Movement distance
|
||||
move = v0 * t + 1 / 2 * a * t * t
|
||||
# 当前位移
|
||||
# Current displacement
|
||||
current += move # type: ignore
|
||||
# 加入轨迹
|
||||
# Add to track
|
||||
track.append(round(move))
|
||||
return track
|
||||
|
||||
|
||||
Reference in New Issue
Block a user