728x90
def var_pos(binary):
r, c = binary.shape
II = []; JJ=[]
for i in range(r):
for j in range(c):
if binary[i, j] > 0:
II.append(i)
JJ.append(j)
var_x = np.var(II)
var_y = np.var(JJ)
return var_x, var_y
def mean_pos(binary):
r, c = binary.shape
II = []; JJ=[]
for i in range(r):
for j in range(c):
if binary[i, j] > 0:
II.append(i)
JJ.append(j)
mean_x = int(np.mean(II))
mean_y = int(np.mean(JJ))
return mean_x, mean_y
dirs = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
def main():
cou = 1
for dir in dirs:
path_dir = './'+dir
file_list = os.listdir(path_dir)
c_a = [];c_b = []
d_a = [];d_b = []
for file in file_list:
file_path = path_dir + '/' + file
img = cv2.imread(file_path, cv2.IMREAD_COLOR)
img = img[20:200, 20:200, :]
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dst = cv2.Canny(gray, 50, 250)
mean_x, mean_y = mean_pos(dst)
A = dst[:mean_x,:]
B = dst[mean_x:,:]
var_x_A, var_y_A = var_pos(A)
var_x_B, var_y_B = var_pos(B)
cv2.imshow('dst', dst)
cv2.waitKey(10)
c_a.append(var_x_A)
d_a.append(var_y_B)
plt.scatter(c_a, d_a)
plt.xlim(0, 500)
plt.ylim(0, 600)
if cou < 8:
plt.pause(1)
else:
break
cou += 1
plt.show()
if __name__ == '__main__':
main()
[결과]
728x90
'파이썬(PYTHON)' 카테고리의 다른 글
Test Data Set (csv) (0) | 2022.05.19 |
---|---|
스도쿠(SUDOKU) 자동화 (0) | 2022.04.15 |
양자 움직임 (작성중) (0) | 2022.03.30 |
트위터 아이디 수집 (collecting twitter ID) - ver 0.1 (0) | 2022.03.23 |
확산 - 파이썬으로 점들의 모임이 임의 움직임 확산 모델링 해봄. (0) | 2022.03.17 |