Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img = cv2.imread('obiekty.png', cv2.IMREAD_GRAYSCALE)
  5. kol = cv2.imread('obiekty.png', cv2.IMREAD_COLOR)
  6.  
  7. image, contours, hierarchy = cv2.findContours(img,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
  8. cont = cv2.drawContours(img, contours, -1, (127,127,127), 3)
  9.  
  10. maly=0
  11. duzy=0
  12.  
  13. for contour in contours:
  14. area = cv2.contourArea(contour)
  15. if area < 1350:
  16. maly=maly+1
  17. cont1 = cv2.drawContours(kol, [contour], -1, (0,0,255), 3)
  18. else:
  19. duzy=duzy+1
  20. cont1 = cv2.drawContours(kol, [contour], -1, (255,0,0), 3)
  21.  
  22. print('Ilosc malych kolek:'+str(maly))
  23. print('Ilosc duzych kolek:'+str(duzy-1))
  24.  
  25. cv2.imshow('Kontur',cont)
  26. cv2.imshow('Output',cont1)
  27. cv2.waitKey(0)
  28. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement