64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
from ximea import xiapi
|
||
import numpy as np
|
||
|
||
cam = xiapi.Camera()
|
||
cam.open_device()
|
||
|
||
|
||
|
||
# self.cam.set_width(1392)
|
||
# cam.set_offsetX(272)
|
||
#
|
||
# cam.set_height(302)
|
||
# cam.set_offsetY(338)
|
||
|
||
|
||
# Serial number = 0031
|
||
cam.set_width(1392)
|
||
cam.set_offsetX(272)
|
||
|
||
cam.set_height(302)
|
||
cam.set_offsetY(406)
|
||
|
||
framerate=20
|
||
|
||
cam.set_framerate(framerate)
|
||
|
||
|
||
# cam.set_aeag_roi_offset_x(self.config_file_object.start_column)
|
||
# cam.set_aeag_roi_offset_y(self.config_file_object.start_row)
|
||
# cam.set_aeag_roi_height(self.config_file_object.end_row - self.config_file_object.start_row)
|
||
# cam.set_aeag_roi_width(self.config_file_object.end_column - self.config_file_object.start_column)
|
||
|
||
|
||
img = xiapi.Image()
|
||
|
||
# 使用相机自动曝光功能得到初始曝光值
|
||
cam.enable_aeag() # 开启自动曝光
|
||
cam.start_acquisition()
|
||
for i in range(10):
|
||
cam.get_image(img) # get data and pass them from camera to img
|
||
cam.stop_acquisition()
|
||
cam.disable_aeag() # 关闭自动曝光
|
||
|
||
|
||
# 根据自动曝光所得初始曝光值,循环迭代获取不过曝的曝光值
|
||
img.get_image_data_numpy()
|
||
image_raw_numpy = img.get_image_data_numpy()
|
||
while image_raw_numpy.max() >= 2730:
|
||
cam.set_exposure(int(0.9 * cam.get_exposure()))
|
||
|
||
cam.start_acquisition()
|
||
cam.get_image(img) # get data and pass them from camera to img
|
||
cam.stop_acquisition()
|
||
image_raw_numpy = img.get_image_data_numpy()
|
||
|
||
# 如果因为光线不足曝光值达到了最大,就将曝光反馈变量设置为1
|
||
if cam.get_exposure() > int(1 / framerate * 10**6):
|
||
cam.set_exposure(int(1 / framerate * 10**6))
|
||
autoexposure_feedback = 1
|
||
else:
|
||
cam.set_exposure(cam.get_exposure())
|
||
|
||
haha=cam.get_exposure()
|