【问题标题】:How to detect glare in image using open-cv python?如何使用opencv python检测图像中的眩光?
【发布时间】:2021-07-01 01:16:36
【问题描述】:

我需要检测以下显示的图像是否为不良图像。任何人都可以提出一种方法或算法来检测眩光并可以对坏图像和好图像进行分类吗?我已经尝试过模板匹配/功能匹配,但它不适用于我的情况。此外,如果可能的话,算法应该独立于环境。

我试过这个算法(模板匹配):

import numpy as np
import cv2
from matplotlib import pyplot as plt

MIN_MATCH_COUNT = 35

img1 = cv2.imread('C:/Users/LB-185/Downloads/imgs/after_thresh/19_12_53_964057.png',0)          # queryImage
img2 = cv2.imread('C:/Users/LB-185/Downloads/imgs/after_thresh/19_12_54_355454.png',0)          # trainImage

sift = cv2.SIFT_create()

kp1, des1 = sift.detectAndCompute(img1,None)       #finding keypoints and descriptors from img 1
kp2, des2 = sift.detectAndCompute(img2,None)       #finding keypoints and descriptors from img 2

FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks = 50)

flann = cv2.FlannBasedMatcher(index_params, search_params)

matches = flann.knnMatch(des1,des2,k=2)

good = []
for m,n in matches:
    if m.distance < 0.7*n.distance:
        good.append(m)
if len(good)>MIN_MATCH_COUNT:
    src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2)
    dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2)

    M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
    matchesMask = mask.ravel().tolist()

    h,w = img1.shape
    pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)
    dst = cv2.perspectiveTransform(pts,M)

    img2 = cv2.polylines(img2,[np.int32(dst)],True,255,3, cv2.LINE_AA)

else:
    print ("Not enough matches are found - {}{}".format(len(good),MIN_MATCH_COUNT))
    matchesMask = None
    
draw_params = dict(matchColor = (0,255,0), singlePointColor = None, matchesMask = matchesMask, flags = 2)# # draw only inliers draw matches in green color

img3 = cv2.drawMatches(img1,kp1,img2,kp2,good,None,**draw_params)
plt.figure(figsize=(20, 20))
plt.imshow(img3, 'gray'),plt.show()

///////////////////////

我必须将下面给定的图像分类为好图像,将上述图像分类为坏图像。

【问题讨论】:

标签: python-3.x opencv image-processing computer-vision


【解决方案1】:

一个简单的阈值方法可能对您很有效。

  1. 将图像转换为灰度。
  2. 例如大于 250 的阈值。
  3. 计算非零的数量。
  4. 如果计数大于图像大小的 1%,则应将图像分类为眩光。

【讨论】:

  • 实际上,我尝试了类似的算法,但我面临的冲突是它会依赖于环境。我需要开发一种独立于环境的算法(不依赖于光源的形状或光源的强度)
  • 我明白了。您可以尝试训练一个简单的 CNN 作为分类器。看看这个:Fast glare detection
  • 好的,我会试试这个。
猜你喜欢
  • 2021-07-09
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多