Skip to content

Instantly share code, notes, and snippets.

View ChongyeWang's full-sized avatar

Chongye Wang ChongyeWang

View GitHub Profile
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)
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
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],
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)
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)
# -*- 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]'
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)
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)
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)
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