Skip to content

Instantly share code, notes, and snippets.

Chongye Wang ChongyeWang

View GitHub Profile
View perspective_and_affine_transforms.py
import cv2
import numpy as np
import matplotlib.pyplot as plt
image = cv2.imread('images/scan.jpg')
cv2.imshow('Original', image)
cv2.waitKey(0)
# Cordinates of the 4 corners of the original image
View edge_detection_image_gradients.py
import cv2
import numpy as np
image = cv2.imread('images/input.jpg',0)
height, width = image.shape
# Extract Sobel Edges
sobel_x = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=5)
sobel_y = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=5)
View dilation_erosion_opening_and_closing.py
import cv2
import numpy as np
image = cv2.imread('images/opencv_inv.png', 0)
cv2.imshow('Original', image)
cv2.waitKey(0)
# Let's define our kernel size
kernel = np.ones((5,5), np.uint8)
View thresholding_binarization_adaptive_thresholding.py
import cv2
import numpy as np
# Load our image as greyscale
image = cv2.imread('images/gradient.jpg',0)
cv2.imshow('Original', image)
# Values below 127 goes to 0 (black, everything above goes to 255 (white)
ret,thresh1 = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)
cv2.imshow('1 Threshold Binary', thresh1)
View date_recognizer.py
# -*- coding: utf-8 -*-
import re
with open('input.txt', 'r') as f:
data = f.read()
normal = "(\d+/\d+/\d+)"
normal_month_date = "(\d+/\d+)"
normal_year = '[0-9][0-9][0-9][0-9]'
View subsets2.py
class Solution(object):
def subsetsWithDup(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums = sorted(nums)
result = []
temp = []
self.backtrack(nums, result, temp, 0)
View subsets.py
class Solution(object):
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums = sorted(nums)
result = []
temp = []
self.backtrack(nums, result, temp, 0)
View sharpening.py
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
cv2.imshow('Original', image)
# Create our shapening kernel, we don't normalize since the
# the values in the matrix sum to 1
kernel_sharpening = np.array([[-1,-1,-1],
[-1,9,-1],
View convolutions_and_blurring.py
import cv2
import numpy as np
image = cv2.imread('images/elephant.jpg')
cv2.imshow('Original Image', image)
cv2.waitKey(0)
# Creating our 3 x 3 kernel
kernel_3x3 = np.ones((3, 3), np.float32) / 9
View bitwise_operations_and_masking.py
import cv2
import numpy as np
# If you're wondering why only two dimensions, well this is a grayscale image,
# if we doing a colored image, we'd use
# rectangle = np.zeros((300, 300, 3),np.uint8)
# Making a sqare
square = np.zeros((300, 300), np.uint8)
cv2.rectangle(square, (50, 50), (250, 250), 255, -2)
You can’t perform that action at this time.