Skip to content

Instantly share code, notes, and snippets.

View yokeshrana's full-sized avatar
🏠
Working from home

Yokesh Rana yokeshrana

🏠
Working from home
View GitHub Profile
@yokeshrana
yokeshrana / vim-enhanced
Last active December 13, 2023 09:14
Customising vim for Mac OS (Big Sur)
1 :: Install Latest Cmake (Using the office dmg )
https://cmake.org/download/
Configure the paths for the cmake using the below command
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
2 :: Default mac os vim lacks python3 support and many other features ,so we will be compiling vim with full features(can limit if u want)
Verify first if Xcode developers tools are installed or not ,if not this will install it in mac
xcode-select --install
Now lets just move on to compiling vim from source on our distribution.
mkdir -p .vim/src
@yokeshrana
yokeshrana / readvideo.py
Created March 8, 2021 08:55
Reading Video using Opencv
import cv2
vid = cv2.VideoCapture("Resources/test_video.mp4")
#since video is stream of pictures we have to use something else here
while True:
success,img=vid.read()
if success:
cv2.imshow("Video", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
@yokeshrana
yokeshrana / readimage.py
Last active March 28, 2021 16:05
Reading images Using OpenCV
import cv2
img = cv2.imread("Resources/lena.png")
cv2.imshow("Picture",img)
cv2.waitKey(3000) # Define the time until it is visible
@yokeshrana
yokeshrana / readFromWebCam.py
Last active March 28, 2021 16:04
Reading from Web Cam
import cv2
vid = cv2.VideoCapture(0) # instead of file path we will use the id of the device (webcam)
#now we define some specific parameter for the webcam
vid.set(3,640)
vid.set(4,480)
#Rest Code is same as basic video read
while vid.isOpened(): # Used to check if camera is opened or not
success,img=vid.read()
if success:
cv2.imshow("Video",img)
@yokeshrana
yokeshrana / gray_scale_blur_dialte_erode.py
Last active March 28, 2021 16:04
Experimenting with Blur ,Dialte and Gray scale Images
import cv2
import numpy as np
img = cv2.imread("Resources/lena.png")
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # converting to it gray scale image
cv2.imshow("GrayScale", imgGray)
# To Blur the image we will use Gaussian Blur to blur
imgBlur = cv2.GaussianBlur(imgGray,(7,7),0) # as a paramter kernel size is passed
cv2.imshow("GrayScaleBlur", imgBlur)
# To detect the edges we use the Canny Filter
@yokeshrana
yokeshrana / image_manipulation.py
Created March 8, 2021 09:17
Resizing the images Cropping the images
import cv2
import numpy as np
img = cv2.imread("Resources/lambo.PNG")
cv2.imshow("Image ", img)
print(img.shape)
'''
Resizing the image
'''
imgResizeinc = cv2.resize(img,(600,600))
print(imgResizeinc.shape)
@yokeshrana
yokeshrana / lines_circle_text_rectange.py
Created March 8, 2021 09:32
Draw Lines ,text ,Rectangle and circle
import cv2
import numpy as np
img = np.zeros((512,512)) # gray scale image (can check by shape also )
# To add the color make it 3 channel
img = np.zeros((512,512,3))
#img[:]=255,0,0
'''
To Draw the line ,Rectange ,Circle and put text on images
'''
cv2.line(img,(0,0),(300,300),(0,255,0),3) # start point ,end point and thickness
@yokeshrana
yokeshrana / stack_images.py
Created March 8, 2021 12:17
Stacking images in one window
"""
Join Images
We will try to put all images in one window
"""
import cv2
import numpy as np
#Function used to stack the images
def stackImages(scale, imgArray):
rows = len(imgArray)
@yokeshrana
yokeshrana / detect_colors.py
Created March 8, 2021 18:30
Detecting Colors in Open CV
import cv2
import numpy as np
'''
Here we will try to detect colors in the image
'''
def empty(a):
pass
# Function used to stack the images
@yokeshrana
yokeshrana / object_detection.py
Created March 8, 2021 19:37
Object detection using OpenCV
import cv2
import numpy as np
path = 'Resources/shapes.png'
img = cv2.imread(path)
imgContour = img.copy()
def stackImages(scale, imgArray):
rows = len(imgArray)
cols = len(imgArray[0])
rowsAvailable = isinstance(imgArray[0], list)
width = imgArray[0][0].shape[1]