|
35 | 35 | assert args.queryPath[-1] == "\\"
|
36 | 36 | assert args.outputPath[-1] == "\\"
|
37 | 37 |
|
38 |
| -# 读取图片 |
| 38 | +# load images |
39 | 39 | sampleImageColorOrigin, sampleImageColorResize, sampleImageGray, queryImagesColorOrigin, queryImagesColorResize, queryImagesGray, numOfQuery, queryFileNames = imageLoad(args.samplePath, args.queryPath)
|
40 | 40 |
|
41 |
| -# 初始化ORB检测对象 |
| 41 | +# initialize ORB detector |
42 | 42 | orb = cv2.ORB_create()
|
43 | 43 |
|
44 |
| -# 初始化FLANN匹配对象 |
| 44 | +# initialize FLANN matcher |
45 | 45 | FLANN_INDEX_KDTREE=0
|
46 | 46 | indexParams=dict(algorithm=FLANN_INDEX_KDTREE,trees=5)
|
47 | 47 | searchParams=dict(checks=50)
|
48 | 48 | flann=cv2.FlannBasedMatcher(indexParams,searchParams)
|
49 | 49 |
|
50 |
| -# 检测与匹配 |
| 50 | +# detect and match |
51 | 51 | keyPointsSample, descriptorsSample, keyPointsQuery, descriptorsQuery, matchesList, goodMatchesList = detectAndMatch(orb, flann, sampleImageGray, queryImagesGray, numOfQuery)
|
52 | 52 |
|
53 |
| -# 计算相似度 |
| 53 | +# caculate similarity |
54 | 54 | similarity = []
|
55 | 55 | for i in range(numOfQuery):
|
56 | 56 | tempSimilarity = caculateSimilarity(goodMatchesList[i], matchesList[i])
|
|
61 | 61 | # print(bestIndex)
|
62 | 62 | # print(similarity)
|
63 | 63 |
|
64 |
| -# 创建输出目录 |
| 64 | +# make dirs for outputs |
65 | 65 | outputPath = args.outputPath
|
66 | 66 | makeDirs(outputPath)
|
67 | 67 |
|
68 |
| -# 保存缩放图片 |
| 68 | +# save resized image |
69 | 69 | resizePath = outputPath + "resize\\"
|
70 | 70 | sampleImageName = args.samplePath.split("\\")[-1].split('.')[-2]
|
71 | 71 | cv2.imwrite(resizePath + sampleImageName + "resize" + ".png", cv2.cvtColor(sampleImageColorResize, cv2.COLOR_RGB2BGR))
|
|
75 | 75 | cv2.imwrite(resizePath + queryName + "Resize" + ".png", cv2.cvtColor(queryImagesColorResize[i],cv2.COLOR_RGB2BGR))
|
76 | 76 | queryImageNames.append(queryName)
|
77 | 77 |
|
78 |
| -# 保存最佳匹配和最高相似度 |
| 78 | +# save best matching image and top similarity |
79 | 79 | cv2.imwrite(outputPath + "BestMatch.png", queryImagesColorOrigin[bestIndex])
|
80 | 80 | saveSimilarity(outputPath, maxSimilarity)
|
81 | 81 |
|
82 |
| -# 显示关键点和匹配情况 |
83 |
| -## 绘制关键点 |
| 82 | +# visualize keypoints and matches |
84 | 83 | figureNameKeypoints = "FinalKeypointsWithSimilarity"
|
85 | 84 | plotKeypoints(sampleImageColorResize, keyPointsSample, queryImagesColorResize, keyPointsQuery, similarity, numOfQuery, outputPath, figureNameKeypoints,isShow=args.isShow)
|
86 | 85 |
|
87 |
| -# 显示匹配点对和相似度 |
88 | 86 | figureNameMatches = "FinalMatchesWithSimilarity"
|
89 | 87 | plotMatches(sampleImageColorResize,keyPointsSample, queryImagesColorResize, keyPointsQuery, similarity, goodMatchesList, numOfQuery, outputPath, figureNameMatches, isShow=args.isShow)
|
90 | 88 |
|
91 |
| -# 序列化关键点和描述子 |
| 89 | +# save keypoints and descriptors |
92 | 90 | saveKeypointsAndDescriptors(
|
93 | 91 | keypoints=keyPointsSample,
|
94 | 92 | kName="keyPoints" + sampleImageName,
|
|
0 commit comments