海康MV-CS200-10GC 工业相机中使用from MvCameraControl_class import *调节白平衡的Python程序
时间: 2024-03-12 20:49:53 浏览: 312
以下是使用MvCameraControl_class调节白平衡的Python程序示例:
```python
from MvCameraControl_class import *
import time
# 枚举设备
deviceList = MV_CC_DEVICE_INFO_LIST()
tlayerType = MV_GIGE_DEVICE | MV_USB_DEVICE
ret = MV_CC_EnumDevices(tlayerType, deviceList)
if ret != 0:
print("enum devices fail! ret[0x%x]" % ret)
sys.exit()
if deviceList.nDeviceNum == 0:
print("no device found!")
sys.exit()
# 打开第一台设备
mvcc_dev_info = cast(deviceList.pDeviceInfo[0], POINTER(MV_CC_DEVICE_INFO)).contents
handle = MV_CC_CreateHandle(mvcc_dev_info)
if handle is None:
print("create handle fail!")
sys.exit()
ret = MV_CC_OpenDevice(handle)
if ret != 0:
print("open device fail! ret[0x%x]" % ret)
sys.exit()
# 设置白平衡为手动
param = MVCC_FLOATVALUE()
ret = MV_CC_GetFloatValue(handle, "BalanceWhiteAuto", param)
print("Get BalanceWhiteAuto: ret[0x%x], fValue[%f]" % (ret, param.fValue))
param.fValue = 0
ret = MV_CC_SetFloatValue(handle, "BalanceWhiteAuto", param)
print("Set BalanceWhiteAuto: ret[0x%x]" % ret)
param.fValue = 1
ret = MV_CC_SetFloatValue(handle, "BalanceWhiteAuto", param)
print("Set BalanceWhiteAuto: ret[0x%x]" % ret)
param.fValue = 0
ret = MV_CC_SetFloatValue(handle, "BalanceWhiteAuto", param)
print("Set BalanceWhiteAuto: ret[0x%x]" % ret)
# 设置白平衡色温为3000K
param = MVCC_FLOATVALUE()
ret = MV_CC_GetFloatValue(handle, "BalanceWhiteManual", param)
print("Get BalanceWhiteManual: ret[0x%x], fValue[%f]" % (ret, param.fValue))
param.fValue = 3000
ret = MV_CC_SetFloatValue(handle, "BalanceWhiteManual", param)
print("Set BalanceWhiteManual: ret[0x%x]" % ret)
# 等待一段时间,让相机可以自适应环境并完成白平衡
time.sleep(5)
# 关闭设备
MV_CC_CloseDevice(handle)
MV_CC_DestroyHandle(handle)
```
需要注意的是,该程序使用了MvCameraControl_class库进行相机控制,需要在程序中引入该库,并且需要根据相机的具体型号和SDK版本进行适当的调整。
此外,需要注意的是该相机的数据类型为float,因此需要在设置参数时将参数类型设置为float,即将设置白平衡色温为3000K的语句修改为:
```python
param.fValue = 3000
ret = MV_CC_SetFloatValue(handle, "BalanceWhiteManual", param)
```
阅读全文