Skip to content

Instantly share code, notes, and snippets.

Chongye Wang ChongyeWang

Block or report user

Report or block ChongyeWang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View arithmetic_operations.py
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
# Create a matrix of ones, then multiply it by a scaler of 100
# This gives a matrix with same dimesions of our image with all values being 100
M = np.ones(image.shape, dtype = "uint8") * 175
# We use this to add this matrix M, to our image
View cropping.py
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
height, width = image.shape[:2]
# Let's get the starting pixel coordiantes (top left of cropping rectangle)
start_row, start_col = int(height * .25), int(width * .25)
# Let's get the ending pixel coordinates (bottom right)
View image_pyramids.py
import cv2
image = cv2.imread('images/input.jpg')
smaller = cv2.pyrDown(image)
larger = cv2.pyrUp(smaller)
cv2.imshow('Original', image )
cv2.imshow('Smaller ', smaller )
View scaling_re-sizing_interpolations.py
import cv2
import numpy as np
# load our input image
image = cv2.imread('images/input.jpg')
# Let's make our image 3/4 of it's original size
image_scaled = cv2.resize(image, None, fx=0.75, fy=0.75)
cv2.imshow('Scaling - Linear Interpolation', image_scaled)
cv2.waitKey()
View rotations.py
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
height, width = image.shape[:2]
# Divide by two to rototate the image around its centre
rotation_matrix = cv2.getRotationMatrix2D((width/2, height/2), 90, .5)
rotated_image = cv2.warpAffine(image, rotation_matrix, (width, height))
View translations.py
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
# Store height and width of the image
height, width = image.shape[:2]
quarter_height, quarter_width = height/4, width/4
View permutations2.py
class Solution(object):
def permuteUnique(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums = sorted(nums)
temp = []
result = []
used = [0 for _ in range(len(nums))]
View permutations.py
class Solution(object):
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
result = []
temp = []
self.backtracking(result, temp, nums)
return result
View comnination_sum2.py
class Solution(object):
def combinationSum2(self, candidates, target):
"""
:type candidates: List[int]
:type target: int
:rtype: List[List[int]]
"""
candidates = sorted(candidates)
result = []
temp = []
View comnination_sum.py
class Solution(object):
class Solution(object):
def combinationSum(self, candidates, target):
"""
:type candidates: List[int]
:type target: int
:rtype: List[List[int]]
"""
res = []
temp = []
You can’t perform that action at this time.