【问题标题】:How to use "xphoto_WhiteBalancer.balanceWhite" with Python and OpenCV?如何在 Python 和 OpenCV 中使用“xphoto_WhiteBalancer.balanceWhite”?
【发布时间】:2018-09-24 21:58:04
【问题描述】:

我正在寻找一种将自动白平衡应用于图像的简单方法。

我找到了一些关于balanceWhite() 方法的官方文档:cv::xphoto::WhiteBalancer Class Reference

但是,当我尝试调用示例中所示的函数时,我遇到了一个模糊的错误。

image = cv2.xphoto_WhiteBalancer.balanceWhite(image)

加注:

Traceback (most recent call last):
  File "C:\Users\Delgan\main.py", line 80, in load
    image = cv2.xphoto_WhiteBalancer.balanceWhite(image)
TypeError: descriptor 'balanceWhite' requires a 'cv2.xphoto_WhiteBalancer' object but received a 'numpy.ndarray'

如果那时我尝试根据需要使用cv2.xphoto_WhiteBalancer 对象:

balancer = cv2.xphoto_WhiteBalancer()
cv2.xphoto_WhiteBalancer.balanceWhite(balancer, image)

它引发:

Traceback (most recent call last):
  File "C:\Users\Delgan\main.py", line 81, in load
    cv2.xphoto_WhiteBalancer.balanceWhite(balancer, image)
TypeError: Incorrect type of self (must be 'xphoto_WhiteBalancer' or its derivative)

有没有人成功地在 Python 3.6 和 OpenCV 3.4 中使用此功能?

我也尝试使用派生类GrayworldWBLearningBasedWBSimpleWB,但错误是一样的。

【问题讨论】:

    标签: python python-3.x opencv image-processing opencv3.0


    【解决方案1】:

    答案可以在xphoto documentation找到。

    创建 WB 算法的适当方法是 createSimpleWB()createLearningBasedWB()createGrayworldWB()

    例子:

    wb = cv2.xphoto.createGrayworldWB()
    wb.setSaturationThreshold(0.99)
    image = wb.balanceWhite(image)
    

    这是官方 OpenCV 存储库中的示例文件:modules/xphoto/samples/color_balance_benchmark.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-16
      • 2011-06-29
      • 1970-01-01
      • 2016-07-06
      • 2022-01-06
      • 1970-01-01
      • 2020-10-18
      • 2019-09-10
      相关资源
      最近更新 更多