ValueError:数学域错误(python)

ValueError:数学域错误(python),python,runtime-error,logarithm,Python,Runtime Error,Logarithm,我正在测试数学模块和PIL模块,并尝试在图像上应用盒计数算法。当我运行下面的代码时,会出现以下错误: Traceback (most recent call last): File "C:\Users\Joao\Desktop\Image Size.py", line 48, in <module> gy.append(math.log(boxCount)) ValueError: math domain error 我发现,如果我将boxcount的值更改为1(而不是

我正在测试数学模块和PIL模块,并尝试在图像上应用盒计数算法。当我运行下面的代码时,会出现以下错误:

Traceback (most recent call last):
  File "C:\Users\Joao\Desktop\Image Size.py", line 48, in <module>
    gy.append(math.log(boxCount))
ValueError: math domain error

我发现,如果我将boxcount的值更改为1(而不是零),则不会产生任何错误,但我需要将boxcount的值更改为0。有人能提出解决方案吗?

因为没有定义负或零的日志。所以请替换:

gy.append(math.log(boxCount))
为此:

gy.append(math.log(boxCount if boxCount>0 else 1))

错误显示可能意味着您正在0上登录。为什么你的箱数是0?你有BMP文件的链接吗?@smushi要使算法工作,初始框数必须为零。是的:
gy.append(math.log(boxCount if boxCount>0 else 1))