Hi im new to opencv ,i need to detect the face mask color .
please do some research before asking here.
we will help with your own effort, but we won’t write your program
i have written the code where it detects the black color everywhere in the picture ,but i want to detect only in the particular region .
Below is the code part.
lower = np.array([0, 0, 0])
upper = np.array([50, 50, 100])
video=cv2.imread('i.jpg')
while True:
image=cv2.flip(image,1,0)
img = cv2.cvtColor(video, cv2.COLOR_BGR2HSV) # Converting BGR image to HSV format
mask = cv2.inRange(img, lower, upper)
mask_contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Finding position of all contours
if len(mask_contours) != 0:
for mask_contour in mask_contours:
if cv2.contourArea(mask_contour) > 500:
x, y, w, h = cv2.boundingRect(mask_contour)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.rectangle(video, (x, y), (x + w, y + h), (0, 0, 255), 3)
cv2.putText(video,'Black',(50,50), font, 1,(0,0,0),2)
cv2.imshow("mask image", mask)
cv2.imshow("window", video)
- Detect the face using this tutorial: OpenCV: Cascade Classifier
- Use your color detection code on the cropped face (after the line
faceROI = frame_gray[y:y+h,x:x+w]
)
Thank you ! I have used this code : COVID-19: Face Mask Detector with OpenCV, Keras/TensorFlow, and Deep Learning - PyImageSearch
on this i need to detect the color of mask