OpenCvで、リアルタイムで、Video を200×200にスライスして、DCT→ローパス→IDCT を行ってみた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import numpy as np import cv2 cap = cv2.VideoCapture(0) w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) fps = cap.get(cv2.CAP_PROP_FPS) while True: ret, frame = cap.read() if frame is None: print("frame is None") break frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) width = 200 xstart = int((w-width)/2) xend = int(xstart + width) ystart = int((h-width)/2) yend = int(ystart + width) subFrame = frame[ystart:yend, xstart:xend] cv2.imshow('Frame', subFrame) dctFrame = cv2.dct(np.array(subFrame, dtype=np.float)) cv2.imshow('DCT', dctFrame) f=20 dctFrame[000:f, f:200]=0 dctFrame[f:200, 000:f]=0 dctFrame[f:200, f:200]=0 idctFrame = cv2.idct(dctFrame) cv2.imshow('LP', dctFrame) cv2.imshow('IDCT', np.array(idctFrame, dtype=np.uint8)) if cv2.waitKey(30) == 27: break cap.release() cv2.destroyAllWindows() |