Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 9b1b5275 authored by Duchamp Solene's avatar Duchamp Solene

Merge branch 'PY/Jupy' into 'master'

Py/jupy

See merge request !9
parents 7e5bf9e8 50de5f7f
This diff is collapsed.
This diff is collapsed.
# import the necessary packages
import numpy as np
import cv2
def is_contour_bad(c):
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
# the contour is 'bad' if it is not a rectangle
return not len(approx) == 4
# load the shapes image, convert it to grayscale, and edge edges in
# the image
image = cv2.imread("Image1.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edged = cv2.Canny(gray, 200, 600)
cv2.imshow("Original", image)
# find contours in the image and initialize the mask that will be
# used to remove the bad contours
(_,cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
mask = np.ones(image.shape[:2], dtype="uint8") * 255
# loop over the contours
for c in cnts:
dictV={}
dictH={}
for pix in c:
if pix[0][0] in dictH.keys():
dictH[pix[0][0]]+=1
else:
dictH[pix[0][0]]=1
if pix[0][1] in dictV.keys():
dictV[pix[0][1]]+=1
else:
dictV[pix[0][1]]=1
print("dictH {}".format(dictH))
print("dictV {}".format(dictV))
# if the contour is bad, draw it on the mask
if is_contour_bad(c):
cv2.drawContours(mask, [c], -1, 0, -1)
# remove the contours from the image and show the resulting images
image = cv2.bitwise_and(image, image, mask=mask)
cv2.imshow("Mask", mask)
cv2.imshow("After", image)
cv2.imwrite("Image1_After.jpg", image)
cv2.waitKey(0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment