如题所述,没找到理想答案,打了一个python的模板,请大佬参考一下(分类:OpenCV):
import cv2
import numpy as np
input = np.array([[1,0,0,0,0],
[1,0,0,0,1],
[0,1,0,1,0],
[0,0,1,0,0],
[0,0,1,1,0]],
np.float32)
se = np.array([[0,1,0],
[1,1,1],
[0,1,0]],
np.uint8)
def myDilate(input, se):
output = np.zeros(input.shape)
for i, row in enumerate(input):
for j, one in enumerate(row):
# your code
output[i][j] = input[i][j]
return output
def myErode(input, se):
output = np.zeros(input.shape)
for i, row in enumerate(input):
for j, one in enumerate(row):
# your code
output[i][j] = input[i][j]
return output
output = myDilate(input, se)
cv_output = cv2.dilate(input, se, iterations=1)
print(output)
print(cv_output)
if(np.array_equal(output, cv_output)):
print("Pass")