【发布时间】: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()
///////////////////////
我必须将下面给定的图像分类为好图像,将上述图像分类为坏图像。
【问题讨论】:
-
请edit 发布您自己的努力来解决这个问题。后者最好在代码中,这称为minimal reproducible example。
标签: python-3.x opencv image-processing computer-vision