color-detection

my OpenCV color detection (red) program doesn't work. it detects all colors instead of red

my OpenCV color detection (red) program doesn't work. it detects all colors instead of red Question: import numpy as np import cv2 img=cv2.imread(‘image.jpg’) hsvFrame=cv2.cvtColor(img ,cv2.COLOR_BGR2HSV) #SET RANGE FOR RED #DEFINE MASk red_lower=np.array([0,0,204],np.uint8) red_upper=np.array([0,0,255],np.uint8) red_mask=cv2.inRange(hsvFrame,red_lower,red_upper) kernel=np.ones((5,5),"uint8") red_mask=cv2.dilate(red_mask,kernel) res_red=cv2.bitwise_and(img,img,mask=red_mask) #creating contour contours,hierarchy=cv2.findContours(red_mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) for pic,contour in enumerate(contours): area=cv2.contourArea(contour) if area>300: x,y,w,h=cv2.boundingRect(contour) imageFrame=cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2) cv2.putText(img,"red colour",(x,y), cv2.FONT_HERSHEY_SIMPLEX,1.0,(0,0,255)) cv2.imshow("detected red ",img) …

Total answers: 1