通过USB摄像头拍摄的图像非常非常非常模糊,想通过图像增强的方式变得清晰一点,效果不怎么好,看实验结果:
- The image taken by the USB camera is very, very fuzzy. I want to make it clearer through image enhancement, but the effect is not very good. See the experimental results:
Code:
import cv2 as cv
#全局直方图均衡化
def eaualHist_demo(image):
gray = cv.cvtColor(image, cv.COLOR_RGB2GRAY) #opencv的直方图均衡化要基于单通道灰度图像
# cv.namedWindow('input_image', cv.WINDOW_NORMAL)
# cv.imshow('input_image', gray)
dst = cv.equalizeHist(gray) #自动调整图像对比度,把图像变得更清晰
cv.namedWindow("eaualHist_demo", cv.WINDOW_NORMAL)
cv.imshow("eaualHist_demo", dst)
return dst
# 局部直方图均衡化
def clahe_demo(image):
gray = cv.cvtColor(image, cv.COLOR_RGB2GRAY)
clahe = cv.createCLAHE(5, (8,8))
dst = clahe.apply(gray)
cv.namedWindow("clahe_demo", cv.WINDOW_NORMAL)
cv.imshow("clahe_demo", dst)
src = cv.imread('./datasets/image20200718220514.jpg')
import numpy as np
from matplotlib import pyplot as plt
plt.hist(src.ravel(),256,[0,256]);
plt.show()
clahe_demo(src)
dst = eaualHist_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
I hope I can help you,If you have any questions, please comment on this blog or send me a private message. I will reply in my free time.