"""Read image and videos """ import cv2 as cv from rescale import rescaleFrame capture = cv.VideoCapture('videos/dog.mp4') # VideoCapture(0) means web cams while True: isTure, frame = capture.read() #capture returns by frame frame_resize = rescaleFrame(frame) cv.imshow('video', frame) cv.imshow('video_resized', frame_resize) if cv.waitKey(20) & 0xFF == ord('d'): # if press 'd' key stop play videos break def changeRes(width, height): '''Live videos''' capture.set(3, width) capture.set(4, height) capture.release() cv.destroyAllWindows() # 비디오 윈도우에서 일정 시간이 지마녀 -215: Assertion failed, # error가 발생한다 -> opencv가 지정한 위치에 미디어 파일을 찾지 못할때 발생 # Video run out of frame -> resize video frame # 위의 에러를 해결하기위해 opencv02 에서 만든 rescaleFrame 함수 사용
import cv2 as cv # reads in BGR format import numpy as np from rescale import rescaleFrame # Original BGR Image original_img = cv.imread('Photos/cert.png') img = rescaleFrame(original_img, 0.4) # cv.imshow('Original_Image', img) blank = np.zeros(img.shape[:2], dtype='uint8') b, g, r = cv.split(img) blue = cv.merge([b, blank, blank]) green = cv.merge([blank, g, blank]) red = cv.merge([blank, blank, r]) cv.imshow('Blue', blue) cv.imshow('Green', green) cv.imshow('Red', red) print(img.shape) print(b.shape) print(g.shape) print(r.shape) merged = cv.merge([b, g, r]) cv.imshow('Merged', merged) cv.waitKey(0)
import cv2 as cv import rescale as rs # Read video capture = cv.VideoCapture('../Videos/dog.mp4') # use integer to capture from webcam/camera, pass file path if reading from video while True: #return boolean if the frame is successfully read | read video frame by frame isTrue, frame = capture.read() frame_resized = rs.rescaleFrame(frame, 0.5) # display individual frame # cv.imshow('Video', frame) cv.imshow('Video Resized', frame_resized) # stopping frame if cv.waitKey(20) & 0xFF==ord('d'): break # release capture pointer from VideoCapture # destroy all opened windows cv.destroyAllWindows()