Opencv 去高光或镜面反射(illuminationChange) | 您所在的位置:网站首页 › 反光膜去除方法 › Opencv 去高光或镜面反射(illuminationChange) |
Opencv 去高光或镜面反射(illuminationChange)_hello_yxc的博客-CSDN博客 如下图片中间存在高光,需要消除高光:
涉及的Opencv API为illuminationChange: 处理后的效果如下:(图片顺序对应src, mask, dst三个参数)
最后处理完的感觉类似拿一块玻璃挡住mask所在的区域。 alpha,beta两个参数共同决定消除高光后图像的模糊程度(范围0~2,0比较清晰,2比较模糊)。 import cv2 import numpy as np def illum(img): # img = cv2.imread("test2.jpg") # img = img[532:768, 0:512] img_bw = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(img_bw, 180, 255, 0)[1] cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1] img_zero = np.zeros(img.shape, dtype=np.uint8) # img[thresh == 255] = 150 for cnt in cnts: x, y, w, h = cv2.boundingRect(cnt) img_zero[y:y+h, x:x+w] = 255 # cv2.imshow("mask", mask) mask = img_zero # cv2.imshow("mask", mask) result = cv2.illuminationChange(img, mask, alpha=1, beta=2) # cv2.imshow("result", result) # cv2.waitKey(0) return result |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |