老师帮我看看错哪了,咋改好
我用的是这个链接的方法,但是报错
代码:
from PIL import Image
def is_white_background(image_path):
# 打开图片
image = Image.open(image_path)
# 将图片转换为RGB模式
image = image.convert("RGB")
# 获取图片尺寸
width, height = image.size
# 遍历每个像素点
for x in range(width):
for y in range(height):
# 获取像素点的RGB值
r, g, b = image.getpixel((x, y))
# 判断RGB值是否接近白色(这里使用阈值判断)
if r < 200 or g < 200 or b < 200:
return False
# 如果所有像素点都接近白色,则判断为白底图
return True
# 测试图片是否是白底图
image_path = "path/to/your/image.jpg"
result = is_white_background(image_path)
if result:
print("该图片是白底图")
else:
print("该图片不是白底图")
报错提示

expected an indented block
Traceback (most recent call last):
File "F:\软件\ShadowBot\shadowbot-5.13.33\python\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "F:\软件\ShadowBot\shadowbot-5.13.33\python\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "F:\软件\ShadowBot\shadowbot-5.13.33\python\lib\site-packages\xbot_interpreter.py", line 94, in <module>
main()
File "F:\软件\ShadowBot\shadowbot-5.13.33\python\lib\site-packages\xbot_interpreter.py", line 49, in main
mod = importlib.import_module(robot_inputs['mod'])
File "F:\软件\ShadowBot\shadowbot-5.13.33\python\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 860, in get_code
File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\asus\AppData\Local\ShadowBot\users\597701452858306562\apps\ce08fa45-b36d-4ebf-8142-009e711f15ab\xbot_robot\process2.py", line 81
for y in range(height):
^
IndentationError: expected an indented block