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
#!/bin/bash | |
#################### | |
### INSTRUCTIONS ### | |
#################### | |
# 1. To speed up things, switch to bt mode and select the right channel (it will make things easier in the next steps) | |
# 2. Switch back to USB mode (so that you can actually enter commands) | |
# 3. Run this script and then quickly switch to bt mode and once the blinking stops hold FN + the corresponding bt channel; | |
# for instance, I have paired it with Windows on channel 1, and on Linux on channel 2, so in my case it's FN + 2. Release it |
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 torch | |
def smart_classify( | |
resized, net, threshold=75, device='cuda', | |
conf_threshold=0.9, debug=False): | |
""" | |
First determined whether the cell is empty or not, checking the number of | |
pixels different from zero. | |
Then use a neural network to classify digits. |
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
from torch.utils.data import Dataset | |
import torch | |
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
import glob | |
import random |
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
def find_empty_grid(x): # checks for empty spaces '0'. | |
for i in range(len(x)): | |
for j in range(len(x[0])): | |
if x[i][j] == 0: | |
return (i, j) # return row, col | |
return None | |
def solve_array(x): |
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 crop_and_warp(img: np.ndarray, crop_rect): | |
""" | |
Crops and warps a rectangular section from an image into a square of | |
similar size. | |
""" | |
# Rectangle described by top left, top right, bottom right and bottom left |
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 operator | |
def find_corners_of_largest_polygon(img: np.ndarray): | |
"""Finds the 4 extreme corners of the largest contour in the image.""" | |
# Find contours | |
contours, h = cv2.findContours( |
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 pre_process_image(img: np.ndarray, skip_dilate: bool=True): | |
""" | |
Uses a blurring function, adaptive thresholding and dilation to expose | |
the main features of an image. | |
""" | |
# Gaussian blur with a kernal size (height, width) of 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 numpy as np | |
from scipy.signal import convolve2d | |
def print_board(board): | |
R, C = board.shape | |
for i in range(R): | |
row = "" | |
for j in range(C): |
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
git clone https://github.com/CSSEGISandData/COVID-19 | |
cd COVID-19 | |
conda create --name jupyter python=3 matplotlib seaborn \ | |
pandas scikit-learn | |
conda activate jupyter | |
conda install -c conda-forge jupyterlab | |
mkdir notebooks | |
jupyter lab |