Я обнаруживаю синий цвет с помощью opencv.Наряду с этим я обнаруживаю точки лица dlib.Поэтому я дал им синий цвет и хочу, чтобы они появлялись у меня на пороге.Проблема в том, что мой код выделяет точки синим цветом, и я получаю их в кадре cv, но он не появляется в моем пороге.
Ниже приведен код, который я написал до сих пор:
from imutils import face_utils
import imutils
import numpy as np
import dlib
import cv2
thresh = 0.25
frame_check = 20
detect = dlib.get_frontal_face_detector()
predict = dlib.shape_predictor(
"shape_predictor_68_face_landmarks.dat") # Dat file is the crux of the code
cap = cv2.VideoCapture(0)
flag = 0
while True:
ret, frame = cap.read()
frame = imutils.resize(frame, width=450)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
subjects = detect(gray, 0)
for subject in subjects:
shape = predict(gray, subject)
shape = face_utils.shape_to_np(shape) # converting to NumPy Array
for (i, (x, y)) in enumerate(shape):
frame=cv2.circle(frame, (x, y), 2, (255, 0, 0), -1)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask2 = cv2.inRange(hsv, np.array([110, 50, 50]), np.array([130, 255, 255]))
res = cv2.bitwise_and(frame, frame, mask=mask2)
gray = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
median = cv2.GaussianBlur(gray, (5, 5), 0)
kernel_square = np.ones((5, 5), np.uint8)
dilation = cv2.dilate(median, kernel_square, iterations=2)
opening = cv2.morphologyEx(dilation, cv2.MORPH_CLOSE, kernel_square)
ret, thresh = cv2.threshold(opening, 30, 255, cv2.THRESH_BINARY)
# thresh = thresh[y:y + h, x:x + w]
contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]
cv2.imshow("thresh", thresh)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
cap.stop()
Может ли dlib перевести очки на молот или я делаю что-то не так?