Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import cv2
  2. from numpy import *
  3.  
  4. test_imgs = ['night_open.jpg', 'night_closed.jpg', 'day_open.jpg', 'day_closed.jpg']
  5.  
  6. for imgFile in test_imgs:
  7. img = cv2.imread(imgFile)
  8. height, width, channels = img.shape
  9. mask = zeros((height+2, width+2), uint8)
  10.  
  11. #the starting pixel for the floodFill
  12. start_pixel = (510,110)
  13. #maximum distance to start pixel:
  14. diff = (2,2,2)
  15.  
  16. retval, rect = cv2.floodFill(img, mask, start_pixel, (0,255,0), diff, diff)
  17.  
  18. print retval
  19.  
  20. #check the size of the floodfilled area, if its large the door is closed:
  21. if retval > 10000:
  22. print imgFile + ": garage door closed"
  23. else:
  24. print imgFile + ": garage door open"
  25.  
  26. cv2.imwrite(imgFile.replace(".jpg", "") + "_result.jpg", img)
  27.  
  28. 681
  29. night_open.jpg: garage door open
  30. 19802
  31. night_closed.jpg: garage door closed
  32. 639
  33. day_open.jpg: garage door open
  34. 19847
  35. day_closed.jpg: garage door closed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement