Skip to content

Instantly share code, notes, and snippets.

View EmanDiab's full-sized avatar

Eman Diab EmanDiab

View GitHub Profile
@EmanDiab
EmanDiab / Transformation
Last active July 12, 2020 15:02
Apply Transformation
pts = screenCntList[0].reshape(4, 2)
# Define our rectangle
rect = order_points(pts)
warped = four_point_transform(orig, screenCntList[0].reshape(4, 2) * ratio)
warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)
T = threshold_local(warped, 11, offset = 10, method = "gaussian")
warped = (warped > T).astype("uint8") * 255
cv2.imshow("Original", image)
@EmanDiab
EmanDiab / check
Created July 12, 2020 13:44
checking part
if not len(screenCntList) >= 2: # there is no rectangle found
print("No rectangle found")
elif scrWidths[0] != scrWidths[1]: # mismatch in rect
print("Mismatch in rectangle")
@EmanDiab
EmanDiab / Contours
Created July 12, 2020 13:14
finding the contours of a document
# find contours in the edged image, keep only the largest ones, and initialize our screen contour
countours, hierarcy = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
imageCopy = image.copy()
# approximate the contour
cnts = sorted(countours, key=cv2.contourArea, reverse=True)
screenCntList = []
scrWidths = []
for cnt in cnts:
@EmanDiab
EmanDiab / Edge Detection
Created July 12, 2020 10:35
Detecting Edges in our image
from skimage.filters import threshold_local
import numpy as np
import cv2
import imutils
image = cv2.imread('your photo name')
ratio = image.shape[0] / 500.0
orig = image.copy()
image = imutils.resize(image, height = 500)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)