Skip to content

Instantly share code, notes, and snippets.

@pknowledge
pknowledge / shape_detection_using_opencv_python.py
Created July 3, 2019 22:29
Simple shape detection Opencv with Python
import numpy as np
import cv2
img = cv2.imread('shapes.jpg')
imgGrey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, thrash = cv2.threshold(imgGrey, 240, 255, cv2.THRESH_BINARY)
contours, _ = cv2.findContours(thrash, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
cv2.imshow("img", img)
for contour in contours:
@pknowledge
pknowledge / adaptive_thresholding_opencv_python.py
Created April 28, 2019 22:26
Adaptive Thresholding Image - OpenCV Python
import cv2 as cv
import numpy as np
img = cv.imread('sudoku.png',0)
_, th1 = cv.threshold(img, 127, 255, cv.THRESH_BINARY)
th2 = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 11, 2);
th3 = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 11, 2);
cv.imshow("Image", img)
cv.imshow("THRESH_BINARY", th1)
@pknowledge
pknowledge / math_func.py
Created October 20, 2018 21:30
Python Unit Testing With Pytest - Using Options with Pytest
def add(x, y=2):
return x + y
def product(x, y=2):
return x * y
@pknowledge
pknowledge / image_blending_using_pyramids _opencv_python.py
Created June 11, 2019 22:05
Image Blending using Pyramids in Opencv python
import cv2
import numpy as np
apple = cv2.imread('apple.jpg')
orange = cv2.imread('orange.jpg')
print(apple.shape)
print(orange.shape)
apple_orange = np.hstack((apple[:, :256], orange[:, 256:]))
# generate Gaussian pyramid for apple
apple_copy = apple.copy()
@pknowledge
pknowledge / opencv_Background_Subtraction.py
Created December 9, 2019 23:15
How to Use Background Subtraction Methods in Python Opencv
import numpy as np
import cv2 as cv
cap = cv.VideoCapture('vtest.avi')
#kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (3,3))
fgbg = cv.bgsegm.createBackgroundSubtractorMOG()
#fgbg = cv.bgsegm.BackgroundSubtractorGMG()
#fgbg = cv.createBackgroundSubtractorMOG2(detectShadows=True)
#fgbg = cv.createBackgroundSubtractorKNN(detectShadows=True)
while True:
ret, frame = cap.read()
@pknowledge
pknowledge / canny_edge_detection_in_opencv.py
Created May 24, 2019 23:48
Canny Edge Detection in OpenCV Python
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread("lena.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
canny = cv2.Canny(img, 100, 200)
titles = ['image', 'canny']
images = [img, canny]
@pknowledge
pknowledge / Clean_PC.ps1
Created March 28, 2020 16:28
Clean PC using powershell
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace(0xA)
$WinTemp = "c:\Windows\Temp\*"
#1# Empty Recycle Bin #
write-Host "Emptying Recycle Bin." -ForegroundColor Cyan
$objFolder.items() | %{ remove-item $_.path -Recurse -Confirm:$false}
#2# Remove Temp
@pknowledge
pknowledge / python_opencv_histograms.py
Created July 10, 2019 20:09
Understanding image Histograms using OpenCV Python
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread("lena.jpg")
#img = np.zeros((200,200), np.uint8)
#cv.rectangle(img, (0, 100), (200, 200), (255), -1)
#cv.rectangle(img, (0, 50), (100, 100), (127), -1)
b, g, r = cv.split(img)
cv.imshow("img", img)
@pknowledge
pknowledge / main.c
Created June 7, 2020 21:21
create a car is controlled from Bluetooth via Android SmartPhone
#include <SoftwareSerial.h> // Import Soft Uart library
#include <Servo.h> // Import Servo library
// Bluetooth communication pins
#define TX 2
#define RX 4
// L298N communication pins
#define IN1 3
#define IN2 5
@pknowledge
pknowledge / math_func.py
Created October 22, 2018 16:02
Python Unit Testing With Pytest - Parameterizing tests
def add(x, y):
return x + y