This file contains 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 | |
# 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) |
This file contains 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 | |
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 |
This file contains 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 | |
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], |
This file contains 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
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) |
This file contains 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
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) |
This file contains 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
# -*- 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]' |
This file contains 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 | |
# 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) |
This file contains 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 | |
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) |
This file contains 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 | |
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) |
This file contains 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 | |
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 |