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
public class ExampleLoopString { | |
public static int frequencyOf(String input, char c) { | |
if (input == null) { | |
return 0; | |
} | |
int ret = 0; | |
for (int i = 0; i < input.length(); i++) { | |
if (input.charAt(i) == c) { | |
ret += 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
import java.io.*; | |
public class ExampleFileIO { | |
public static void main(String[] args) { | |
try (InputStream is = ExampleFileIO.class.getClassLoader().getResourceAsStream("list.txt"); | |
InputStreamReader reader = new InputStreamReader(is); | |
BufferedReader bufferedReader = new BufferedReader(reader); | |
) { | |
String s; |
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
public class EnumExample { | |
enum Seasons { | |
WINTER, SPRING, SUMMER, FALL; | |
} | |
public static boolean needJacket(Seasons s){ | |
return s == Seasons.WINTER || s == Seasons.FALL; | |
} |
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
data "http" "example" { | |
url = "https://checkpoint-api.hashicorp.com/v1/check/terraform" | |
# Optional request headers | |
request_headers = { | |
Accept = "application/json" | |
} | |
} | |
output "example" { |
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 | |
def thresh(src, img, low, ty): | |
_, mask = cv2.threshold(img, low, 256, ty) | |
splits = [cv2.bitwise_and(x, mask) for x in cv2.split(src)] | |
return cv2.merge(splits) | |
img = cv2.imread("rubiks.png") |
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 | |
""" | |
Starting motivation [https://docs.opencv.org/3.2.0/df/d9d/tutorial_py_colorspaces.html] | |
RGB has no concept of hue unlike HS* (in this case we will do HSV). While we can extract it, it's not as straightforward | |
as with HSV. In our image, let's say we want to find the green parts. In HSV, we can do a pretty good job by just with | |
just an arc in the hue and then a fixed saturation range and value. Green can only exist in ~[90,150] degrees. Given |
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 | |
def dog(img, k2=(7, 7), k1=(3, 3), denoise=False, denoise_k=3): | |
blur1 = cv2.GaussianBlur(img, k1, 1) | |
blur2 = cv2.GaussianBlur(img, k2, 1) | |
diff = blur1 - blur2 | |
if denoise: | |
diff = cv2.medianBlur(diff, denoise_k) | |
return diff |
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 matplotlib.pyplot as plt | |
kernel = (7, 7) | |
imgs = { | |
"salt_n_pepper": cv2.imread("Noise_salt_and_pepper.png"), # thank you wikipedia | |
"wrinkles": cv2.imread("old_man.jpeg"), # images.pexels.com | |
"tripod": cv2.imread("tripod.png") # classic b/w man looking at camera on tripod | |
} |
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 | |
def get_img(cap): | |
ret, frame = cap.read() | |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
return frame |
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 | |
from matplotlib import pyplot as plt | |
def before_after(bef, af): | |
""" | |
refactor out the matplot lib thing | |
""" | |
plt.subplot(121), plt.imshow(bef, 'gray') | |
plt.subplot(122), plt.imshow(af, 'gray') |
NewerOlder