Window sliding 구현하고 Convolution 만들어봐야지 하고 미루다가 프로젝트 할 때 사용할 일이 있어서 구현해봤다.
시험기간이라 설명은 나중에 ..
커널은 edge 표현을 위해 sobel mask를 사용해봤다.
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from PIL import ImageDraw
import cv2
Array = cv2.imread('frame_00000.jpg')
Array = cv2.cvtColor(Array,cv2.COLOR_BGR2GRAY)#np.ones((100,100))
print(Array.shape)
#mask = np.zeros((6,6))
Array = cv2.resize(Array,(480,270))
mask = np.array([[-1,-2,-1],
[0,0,0],
[1,2,1]])
print(mask.shape)
max_window = np.array([Array.shape[0],Array.shape[1]])
now_window = np.array([mask.shape[0],mask.shape[1]])
min_window = np.array([0,0])
Conv_feature=np.zeros((Array.shape[0]-mask.shape[0]+1,Array.shape[1]-mask.shape[1]+1))
Conv_where = np.array([0,0])
while(1):
if max_window[0] <now_window[0]:
now_window=[mask.shape[0],now_window[1]+1]
min_window=[0,min_window[1]+1]
if Conv_feature.shape[0] == Conv_where[0]:
Conv_where[0]=0
Conv_where[1]+=1
#if max_window[1]+1 <now_window[1]:
#break
if Conv_feature.shape[1] == Conv_where[1]:
break
Conv_feature[Conv_where[0],Conv_where[1]]=np.sum(Array[min_window[0]:now_window[0],min_window[1]:now_window[1]]*mask)
Conv_where[0]+=1
now_window[0]+=1
min_window[0]+=1
plt.imshow(Conv_feature,cmap='gray')
plt.show()
'maengkyun > CV' 카테고리의 다른 글
depth (0) | 2021.11.28 |
---|---|
ZED2 stereo camera python api setup (0) | 2021.11.27 |
[Computer Vision] Sliding Window Algorithm (0) | 2021.11.12 |
끄적 (0) | 2021.08.25 |