vk0608 2023-05-29 16:06 采纳率: 0%
浏览 1425

opencvSSIM评价质量报错提示必须指定data_range参数,如何解决?

之前能成功运行的代码现在出错怎么处理
'Since image dtype is floating point, you must specify '
'the data_range parameter. Please read the documentation '
'carefully (including the note). It is recommended that '
'you always specify the data_range anyway.')

img

  • 写回答

1条回答 默认 最新

  • IT论之程序员 2023-05-30 19:30
    关注
    
    这是因为OpenCV在比较最近的版本中修改了SSIM的接口,添加了data_range这个参数。
    解决方法很简单,只需要在调用cv2.SSIM()时指定data_range参数即可。
    data_range 参数代表图像像素值的范围,对于uint8来说是[0, 255], float32来说是[0, 1]。
    所以如果你的图像是:
    - uint8类型,则设置data_range=(255, 255)
    - float32类型,则设置data_range=(1.0, 1.0)
    例如:
    python
    # For uint8 images
    score, diff = cv2.SSIM(img1, img2, data_range=(255, 255)) 
    
    # For float32 images 
    score, diff = cv2.SSIM(img1, img2, data_range=(1.0, 1.0))
    所以你只需要根据图像的数据类型添加data_range参数,就可以解决这个报错,让代码正常运行了。
    希望能帮助到你!有任何其他问题 feel free to ask。
    
    评论

报告相同问题?

问题事件

  • 创建了问题 5月29日