Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- import os
- lit = 'RGB_image_path/rgb_image.png'
- mask = 'mask_image_path/maks_image.png'
- lit_image = cv2.imread(lit)
- mask_image = cv2.imread(mask)
- imgray=cv2.cvtColor(mask_image,cv2.COLOR_BGR2GRAY)
- ret,thresh = cv2.threshold(imgray,127,255,1)
- image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
- if len(contours)>0:
- print('length is: ',len(contours))
- cnt = contours[0]
- x,y,w,h = cv2.boundingRect(cnt)
- draw_rec_lit_image=cv2.rectangle(lit_image,(x,y),(x+w,y+h),(0,0,255),2)
- if cv2.waitKey() == ord('q'): #press q to close the output image window
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement