Skip to content

Instantly share code, notes, and snippets.

View vardanagarwal's full-sized avatar
🌚

Vardan Agarwal vardanagarwal

🌚
View GitHub Profile
def action(input_char, replace_with, move, new_state):
global tapehead, state
if tape[tapehead] == input_char:
tape[tapehead] = replace_with
state = new_state
if move == 'L':
tapehead -= 1
else:
tapehead += 1
return True
string = input("Enter String: ")
length = len(string) + 2
tape = ['B']*length
i = 1
tapehead = 1
for s in string: #loop to place string in tape
tape[i] = s
i += 1
state = 0
@vardanagarwal
vardanagarwal / car.ino
Created January 22, 2020 08:17
Arduino joystick car code
const int IN1 = 2;
const int IN2 = 3;
const int IN3 = 4;
const int IN4 = 5;
const int LEDPin[] = {6, 7, 8, 9};
const int ENA = 10;
const int ENB = 11;
const int SW = 12;
const int joystickAnalog[] = {A0, A1};
const int IRPin[] = {A2, A3, A4, A5};
import cv2
import numpy as np
img = cv2.imread('Paris.jpg')
original = img.copy()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # convert image to HSV color space
hsv = np.array(hsv, dtype = np.float64)
hsv[:,:,1] = hsv[:,:,1]*1.25 # scale pixel values up for channel 1
hsv[:,:,1][hsv[:,:,1]>255] = 255
hsv[:,:,2] = hsv[:,:,2]*1.25 # scale pixel values up for channel 2
import cv2
import numpy as np
img = cv2.imread('Paris.jpg')
dst = cv2.detailEnhance(img, sigma_s=10, sigma_r=0.15)
#sigma_s controls how much the image is smoothed - the larger its value,
#the more smoothed the image gets, but it's also slower to compute.
#sigma_r is important if you want to preserve edges while smoothing the image.
#Small sigma_r results in only very similar colors to be averaged (i.e. smoothed), while colors that differ much will stay intact.
kernel_sharpening = np.array([[-1,-1,-1],
import cv2
img = cv2.imread('Paris.jpg')
res = cv2.bitwise_not(img)
cv2.imshow('original', img)
cv2.imshow('img', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
def gamma_function(channel, gamma):
invGamma = 1/gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8") #creating lookup table
channel = cv2.LUT(channel, table)
return channel
img = cv2.imread('Paris.jpg')
import cv2
def gamma_function(channel, gamma):
invGamma = 1/gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
channel = cv2.LUT(channel, table)
return channel
img = cv2.imread('Paris.jpg')
import cv2
import numpy as np
img = cv2.imread('Paris.jpg')
image_HLS = cv2.cvtColor(img,cv2.COLOR_BGR2HLS) # Conversion to HLS
image_HLS = np.array(image_HLS, dtype = np.float64)
daylight = 1.15
image_HLS[:,:,1] = image_HLS[:,:,1]*daylight # scale pixel values up for channel 1(Lightness)
image_HLS[:,:,1][image_HLS[:,:,1]>255] = 255 # Sets all values above 255 to 255
image_HLS = np.array(image_HLS, dtype = np.uint8)
import cv2
import numpy as np
img = cv2.imread('Paris.jpg')
height, width = img.shape[:2]
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = 0.8 # creating threshold. This means noise will be added to 80% pixels
for i in range(height):
for j in range(width):
if np.random.rand() <= thresh: