Learn Before
Concept
Code Example:
import numpy as np import cv2 img = cv2.imread('opencv-logo.png') imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(imgray, 127, 255, 0) contours, hierarchy = cv2.findCountours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) print("Number of Contours = " + str(len(contours)) cv2.drawContours(img, contours, -1, (0, 255, 0) , 3) cv2.imshow('Image', img) cv2.imshow('Image gray', imgray) cv2.waitkey(0) cv2.destroyAllWindows()
0
1
Updated 2021-07-24
Tags
Python Programming Language
Data Science