我正在寻找一种将自动白平衡应用于图像的简单方法。
我找到了一些关于 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 中使用此功能吗?
我还尝试使用派生类 GrayworldWB
、LearningBasedWB
和 SimpleWB
,但错误是相同的。
最佳答案
答案可以在 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
关于python - 如何在 Python 和 OpenCV 中使用 "xphoto_WhiteBalancer.balanceWhite"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49835662/