我需要检测以下显示的图像是否为不良图像。有谁能提供一种方法或算法来检测眩光,并对不良图像和良好图像进行分类?我尝试过模板匹配/特征匹配,但它不适用于我的情况。此外,如果可能,算法应独立于环境工作。
x1c 0d1x
我尝试过这个算法(模板匹配):
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()
//////////////////////////
我不得不把下面给出的图像分类为好图像和上面提到的图像为坏图像。
1条答案
按热度按时间lsmd5eda1#
一个简单的阈值方法可能会很适合你。
1.将图像转换为灰度。
1.例如,大于250的阈值。
1.计算非零的数目。
1.如果该计数大于图像尺寸的比如1%,则该图像应当被分类为眩光。