This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
def write_video_from_webcam(): | |
"""Write a video file from webcam | |
""" | |
vid_cap = cv2.VideoCapture(0) | |
# set frame size and fps | |
frame_width = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
def show_video(vid_cap: cv2.VideoCapture): | |
"""Show video from a VideoCapture object | |
Args: | |
vid_cap (cv2.VideoCapture): VideoCapture object | |
""" | |
if vid_cap.isOpened() == False: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# preprocess | |
image = cv2.imread("a.jpg").astype(float) # convert uint8 to float | |
image = image / 255 # normalize to [0, 1] | |
# add noise | |
mean, std = 0, 0.1 | |
noise = np.random.normal(mean, std, image.shape) # generate gaussian noise |