|
|
|
|
|
""" |
|
Created on Sat Aug 3 22:20:23 2024 |
|
|
|
@author: ysnrfd |
|
""" |
|
|
|
import cv2 |
|
import numpy as np |
|
from skimage import exposure, img_as_float |
|
from scipy.ndimage import gaussian_filter |
|
|
|
def enhance_image(image): |
|
|
|
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) |
|
|
|
|
|
gray_image_float = img_as_float(gray_image) |
|
|
|
|
|
log_transformed = np.log1p(gray_image_float * 255) |
|
|
|
|
|
log_transformed = exposure.rescale_intensity(log_transformed, in_range='image') |
|
|
|
|
|
denoised_image = gaussian_filter(log_transformed, sigma=1) |
|
|
|
|
|
enhanced_image = (denoised_image * 255).astype(np.uint8) |
|
|
|
|
|
enhanced_image = exposure.equalize_hist(enhanced_image) * 255 |
|
enhanced_image = enhanced_image.astype(np.uint8) |
|
|
|
|
|
enhanced_image = cv2.cvtColor(enhanced_image, cv2.COLOR_GRAY2BGR) |
|
|
|
return enhanced_image |
|
|
|
|
|
cap = cv2.VideoCapture(0) |
|
|
|
while True: |
|
|
|
ret, frame = cap.read() |
|
|
|
if not ret: |
|
break |
|
|
|
|
|
enhanced_frame = enhance_image(frame) |
|
|
|
|
|
cv2.imshow('Night Vision', enhanced_frame) |
|
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord('q'): |
|
break |
|
|
|
|
|
cap.release() |
|
cv2.destroyAllWindows() |
|
|