Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3. import os
  4.  
  5. lit = 'RGB_image_path/rgb_image.png'
  6. mask = 'mask_image_path/maks_image.png'
  7.  
  8. lit_image = cv2.imread(lit)
  9. mask_image = cv2.imread(mask)
  10.  
  11. imgray=cv2.cvtColor(mask_image,cv2.COLOR_BGR2GRAY)
  12. ret,thresh = cv2.threshold(imgray,127,255,1)
  13. image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
  14.  
  15. if len(contours)>0:
  16. print('length is: ',len(contours))
  17. cnt = contours[0]
  18. x,y,w,h = cv2.boundingRect(cnt)
  19.  
  20. draw_rec_lit_image=cv2.rectangle(lit_image,(x,y),(x+w,y+h),(0,0,255),2)
  21.  
  22.  
  23. if cv2.waitKey() == ord('q'): #press q to close the output image window
  24. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement