Professional Documents
Culture Documents
Étiquettage
Étiquettage
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('lena.jpg',0)
imgBlurred = cv.GaussianBlur(img, (5,5), 0)
imgThresh = cv.adaptiveThreshold(imgBlurred, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C,
cv.THRESH_BINARY_INV, 11,2)
imgThreshCopy = imgThresh.copy()
npaContours, npaHierarchy = cv.findContours(imgThreshCopy, cv.RETR_EXTERNAL,
cv.CHAIN_APPROX_SIMPLE)
for npaContour in npaContours:
[intX, intY, intWidth, intHeight] = cv.boundingRect(npaContour)
cv.rectangle(img,
(intX, intY),
(intX + intWidth, intY + intHeight),
(0, 255, 0),
2)