Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- img = cv2.imread('obiekty.png', cv2.IMREAD_GRAYSCALE)
- kol = cv2.imread('obiekty.png', cv2.IMREAD_COLOR)
- image, contours, hierarchy = cv2.findContours(img,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
- cont = cv2.drawContours(img, contours, -1, (127,127,127), 3)
- maly=0
- duzy=0
- for contour in contours:
- area = cv2.contourArea(contour)
- if area < 1350:
- maly=maly+1
- cont1 = cv2.drawContours(kol, [contour], -1, (0,0,255), 3)
- else:
- duzy=duzy+1
- cont1 = cv2.drawContours(kol, [contour], -1, (255,0,0), 3)
- print('Ilosc malych kolek:'+str(maly))
- print('Ilosc duzych kolek:'+str(duzy-1))
- cv2.imshow('Kontur',cont)
- cv2.imshow('Output',cont1)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement