Skip to content

Instantly share code, notes, and snippets.

View palaashatri's full-sized avatar
:shipit:
I may be slow to respond.

Palaash Atri palaashatri

:shipit:
I may be slow to respond.
View GitHub Profile
# Enter your code here. Read input from STDIN. Print output to STDOUT
import collections
x = int(input())
str_num = input().split( )
numbers = []
for num in str_num:
numbers.append(int(num))
@palaashatri
palaashatri / opencv_video_capture.py
Last active August 12, 2020 06:03
A simple application demonstrating video capture using Webcam on OpenCV
# A simple program that captures video from webcam and displays it on the screen
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret,frame = cap.read()
frame = cv2.resize(frame,(0,0),fx = 0.5, fy = 0.5)
@palaashatri
palaashatri / opencv_drawing app.py
Created August 12, 2020 05:52
A simple drawing app made on OpenCV on Python3
import numpy as np
import cv2
# Global Variables
canvas = np.ones([500,500,3],'uint8')*255
radius = 3
color = (0,255,0)
pressed = False
# click callback
@palaashatri
palaashatri / opencv_ds.py
Last active August 12, 2020 06:01
Demonstration of OpenCV Data Types and Data Structures from an image
import numpy as np
import cv2
black = np.zeros([150,200,1],'uint8')
cv2.imshow("Black",black)
print(black[0,0,:])
ones = np.ones([15,200,3],'uint8')
cv2.imshow("Ones",ones)
print(ones[0,0,:])
@palaashatri
palaashatri / opencv_filters.py
Created August 12, 2020 06:00
Demonstration of OpenCV Gaussian Blur, Dilation and Erosion filters on an image
import numpy as np
import cv2
image = cv2.imread("image.jpg")
cv2.imshow("Original",image)
#@ Gaussian Blur :
# Gaussian Blur filter smooths an image by averaging pixel values with its neighbors.
# It's called a Gaussian Blur because the average has a Gaussian falloff effect.
# In other words, pixels that are closer to the target pixel have a higher impact with the average than pixels that are far away.
@palaashatri
palaashatri / opencv_channels.py
Created August 12, 2020 06:01
Demonstration of BGR and HSV channels of an image in OpenCV
import numpy as np
import cv2
color = cv2.imread("image.jpg",1) # Read image in color (1) mode
cv2.imshow("Image",color)
cv2.moveWindow("Image",0,0)
print(color.shape)
height,width,channels = color.shape
b,g,r = cv2.split(color) # Split image into Blue, Green and Red channels
@palaashatri
palaashatri / opencv_img_transformation.py
Created August 12, 2020 06:02
Demonstation of OpenCV image transformation techniques (Scaling and Rotation)
import numpy as np
import cv2
img = cv2.imread("image.jpg")
# Scale
img_half = cv2.resize(img,(0,0),fx=0.5,fy=0.5)
img_stretch = cv2.resize(img,(600,600))
img_stretch_near = cv2.resize(img,(600,600),interpolation=cv2.INTER_NEAREST)
@palaashatri
palaashatri / opencv_simple_thresholding.py
Last active August 12, 2020 06:16
Slow Binary Thresholding (Binary Segmentation) of an image using OpenCV
import numpy as np
import cv2
bw = cv2.imread("image.pmg",0) # read as BmW
height,width = bw.shape[0:2]
cv2.imshow("Original BW",bw)
binary = np.zeros([height,width,1],'uint8')
thresh = 85
@palaashatri
palaashatri / SimpleHTTPServerWithUpload.py
Created September 15, 2020 14:04 — forked from touilleMan/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload - Python3 version
#!/usr/bin/env python3
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
see: https://gist.github.com/UniIsland/3346170
"""
@palaashatri
palaashatri / blockchain-env-setup.md
Last active November 28, 2020 08:06
Setting up the blockchain developer environment for Hyperledger Fabric and Ethereum on Ubuntu.
  • Install and run docker engine, git and curl -
sudo apt-get update
sudo apt-get install git -y
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common -y