好友
阅读权限20
听众
最后登录1970-1-1
|
本帖最后由 onoffon 于 2022-5-10 08:44 编辑
看到一个函数
[Python] 纯文本查看 复制代码 def matchAB(fileA, fileB):
# 读取图像数据
imgA = cv2.imread(fileA)
imgB = cv2.imread(fileB)
# 转换成灰色
grayA = cv2.cvtColor(imgA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imgB, cv2.COLOR_BGR2GRAY)
# 获取图片A的大小
height, width = grayA.shape
# 取局部图像,寻找匹配位置
result_window = np.zeros((height, width), dtype=imgA.dtype)
for start_y in range(0, height-100, 10):
for start_x in range(0, width-100, 10):
window = grayA[start_y:start_y+100, start_x:start_x+100]
match = cv2.matchTemplate(grayB, window, cv2.TM_CCOEFF_NORMED)
_, _, _, max_loc = cv2.minMaxLoc(match)
[color=Black]matched_window = grayB[max_loc[1]:max_loc[1]+100, max_loc[0]:max_loc[0]+100][/color][b][color=Red] [/color][/b] #[ : , : ] 为什么能这样表达
result = cv2.absdiff(window, matched_window)
[color=Red]result_window[start_y:start_y+100, start_x:start_x+100] = result[/color]
plt.imshow(result_window)
plt.show()
matched_window = grayB[max_loc[1]:max_loc[1]+100, max_loc[0]:max_loc[0]+100]
result_window[start_y:start_y+100, start_x:start_x+100] = result
红色那两句,列表中 [ : , : ] 这种表达方式是什么意思,为什么能有这种方式?如果这样:
x = ["a123","b234","c345","d","e", "f"]
print(x[1:2, 4:5])
则会报错?
|
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|