Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Try this:

!/usr/bin/python3.8.1

OpenCV 4.2.0, Raspberry pi 3/3b/4b, Buster v10

Date: 20th January, 2020

import cv2

img = cv2.imread('bio.png') imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(imgray, 50, 255, 0) contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) print("Number of contours = {}".format(str(len(contours)))) print('contours {}'.format(contours[0]))

cv2.drawContours(img, contours, -1, (0, 255, 0), 2) cv2.drawContours(imgray, contours, -1, (0, 255, 0), 3)

cv2.imshow('Image', img) cv2.imshow('Image GRAY', imgray) cv2.waitKey(0) cv2.destroyAllWindows()

Output:

image description

Try this:

!/usr/bin/python3.8.1

OpenCV
#!/usr/bin/python3.8.1
#OpenCV 4.2.0, Raspberry pi 3/3b/4b, Buster v10

Date: v10 #Date: 20th January, 2020

2020 import cv2

import cv2

img = cv2.imread('bio.png') imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(imgray, 50, 255, 0) contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) print("Number of contours = {}".format(str(len(contours)))) print('contours {}'.format(contours[0]))

{}'.format(contours[0]))

cv2.drawContours(img, contours, -1, (0, 255, 0), 2) cv2.drawContours(imgray, contours, -1, (0, 255, 0), 3)

3)

cv2.imshow('Image', img) cv2.imshow('Image GRAY', imgray) cv2.waitKey(0) cv2.destroyAllWindows()

cv2.destroyAllWindows()

Output:

image description