Skip to content

Instantly share code, notes, and snippets.

View imxtx's full-sized avatar
🎯
Focusing

T.X. Xie imxtx

🎯
Focusing
View GitHub Profile
@imxtx
imxtx / write_video_from_webcam.py
Created June 10, 2022 16:10
Write video from webcam using OpenCV
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))
@imxtx
imxtx / read_video.py
Last active June 10, 2022 15:42
Read video file and webcam using OpenCV
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:
@imxtx
imxtx / add_gaussian_noise.py
Last active May 10, 2022 04:22
Add gaussian noise to an image using OpenCV and Numpy
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