Я получаю изображения с тепловизионной камеры FLIR через API Spinnaker.
Я показываю изображения с помощью OpenCV и одновременно показываю гистограмму изображения с использованием Matplotlib. Соответствующий фрагмент кода (который находится в функции, которая также содержит настройку камеры и обработку ошибок)
Код: Выделить всё
cam.BeginAcquisition()
print('Acquiring images...')
print('Press enter to close the program..')
fig = plt.figure(1)
fig.canvas.mpl_connect('close_event', handle_close)
acq_count = 0 # number of saved images
# Retrieve and display images
while(continue_recording):
try:
image_result = cam.GetNextImage(1000)
# Ensure image completion
if image_result.IsIncomplete():
print('Image incomplete with image status %d ...' % image_result.GetImageStatus())
else:
# Getting the image data as a numpy array
image_data = image_result.GetNDArray()
image_data = cv2.rotate(image_data, cv2.ROTATE_90_COUNTERCLOCKWISE)
image_data = cv2.flip(image_data, 1)
image_copy = image_data
count, bins = np.histogram(image_data.flatten())
cv2.imshow("FLIR", image_data)
plt.stairs(count, bins)
plt.pause(0.001)
plt.clf()
# if 's' pressed then save image data
if cv2.waitKey(100) & 0xFF == ord('s'):
f_name = "test_" + str(acq_count) + '.png'
cv2.imwrite(f_name, image_data)
acq_count += 1
# If user presses enter, close the program
if keyboard.is_pressed('ENTER'):
print('Program is closing...')
cv2.destroyAllWindows()
plt.close('all')
input('Done! Press Enter to exit...')
continue_recording=False
image_result.Release() # clears camera buffer
except PySpin.SpinnakerException as ex:
print('Error: %s' % ex)
return False
cam.EndAcquisition()
EDIT :: Я также должен отметить, что все работает нормально, пока нет рисунка Matplotlib.>
Подробнее здесь: https://stackoverflow.com/questions/760 ... re-instead
Мобильная версия