如何将"xphoto_WhiteBalancer.balanceWhite"与Python和OpenCV一起使用?



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

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

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

image = cv2.xphoto_WhiteBalancer.balanceWhite(image)

提高:

Traceback (most recent call last):
  File "C:UsersDelganmain.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:UsersDelganmain.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,但错误是相同的。

答案可以在xphoto文档中找到。

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

例:

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

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

最新更新