import numpy as np import cv2 import math print("version openCV:"+str( cv2.__version__ )) flags = [i for i in dir(cv2) if i.startswith('COLOR_')] print("conversions supportées:"+ str(flags)) #exit(0) #Load an color image in grayscale img = cv2.imread('img.jpg',0) print("img:" +str(img) ) # Create a black image #img = np.zeros((512,512,3), np.uint8) # Draw a diagonal blue line with thickness of 5 px cv2.line(img,(0,0),(511,511),255,5,cv2.LINE_AA) font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(img,'BUT3',(10,500), font, 4,255,2,cv2.LINE_AA) cv2.imwrite('imggray.png',img) #load image in color img = cv2.imread('img.jpg',1) px = img[100,100] print("px:"+str(px)) img[200,100] = [255,0,0] px = img[200,100] print("px:"+str(px)) for i in range(0,255): for j in range(0,255): img[200+j,100+i]=[i,j,0] print("img.shape:"+str(img.shape)) print("img.dtype:"+str(img.dtype)) xo=692 yo=252 larg=60 haut=60 x1=434 y1=218 ROI = img[yo:yo+haut, xo:xo+larg] for i in range(0,3): img[y1+i*100:y1+haut+i*100, x1:x1+larg] = ROI # Convert BGR to HSV hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # define range of blue color in HSV lower_blue = np.array([110,50,50]) upper_blue = np.array([130,255,255]) # Threshold the HSV image to get only blue colors mask = cv2.inRange(hsv, lower_blue, upper_blue) # Bitwise-AND mask and original image res = cv2.bitwise_and(img,img, mask= mask) xgazon=350 ygazon=618 print("gazon:"+str(hsv[ygazon,xgazon])) #gazon:[ 36 171 183] lower_gazon = np.array([26,50,50]) upper_gazon= np.array([46,255,255]) # Threshold the HSV image to get only blue colors mask = cv2.inRange(hsv, lower_gazon, upper_gazon) # Bitwise-AND mask and original image mask= cv2.bitwise_not( mask) res = cv2.bitwise_and(img,img, mask= mask) cv2.imwrite('imgres.png',res) cv2.imshow('image res',res) cv2.imwrite('imgcolor.png',img) cv2.imshow('image',img) cv2.waitKey(0) cv2.destroyAllWindows()