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("flags:"+str(flags)) # Load an color image in grayscale img = cv2.imread('img.jpg',0) print(img) # Create a black image #img = np.zeros((512,512,3), np.uint8) #pour une image couleur #cv2.line(img,(0,0),(511,511),(255,0,0),5) cv2.line(img,(0,0),(511,511),128,5) font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(img,'BUT3',(10,500), font, 4,255,2,cv2.LINE_AA) cv2.imwrite('imggray.png',img) #--------------------------------- # Load an color image in color img = cv2.imread('img.jpg',1) print(img) cv2.imwrite('imgcolor.png',img) px = img[100,100] print("px:" + str(px)) blue = img[100,100,0] print("blue:" +str(blue)) print("image shape: " +str(img.shape)+" , image type:" +str(img.dtype)) yo=257 xo=695 larg=60 haut=60 ROI=img[yo:yo+haut, xo:xo+larg] x1=435 y1=220 img[y1:y1+haut, x1:x1+larg] = ROI for i in range(0,3): x1=435+i*120 y1=220 img[y1:y1+haut, x1:x1+larg] = ROI for r in range(0,256): for g in range(0,256): img[100+g,100+r]=(100,g,r) # 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]) xgazon=346 ygazon=641 print("gazon:"+ str(hsv[ygazon,xgazon])) lower_gazon = np.array([38-10,50,50]) upper_gazon = np.array([38+10,255,255]) # Threshold the HSV image to get only blue colors #mask = cv2.inRange(hsv, lower_blue, upper_blue) mask = cv2.inRange(hsv, lower_gazon, upper_gazon) mask=cv2.bitwise_not(mask) # Bitwise-AND mask and original image imgres = cv2.bitwise_and(img,img, mask= mask) cv2.imwrite('imgres.png',imgres) #cv2.imshow('image',img) cv2.imshow('image',imgres) cv2.waitKey(0) cv2.destroyAllWindows()