This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |