我正在使用 mediapipe facedetector 解决方案裁剪嘴部区域。我成功地在嘴巴区域制作了边界框,但我无法裁剪视频。
这是我的代码:
import cv2
import mediapipe as mp
import numpy as np
mpFaceDetection = mp.solutions.face_detection
faceDetection = mpFaceDetection.FaceDetection(model_selection=1)
cap = cv2.VideoCapture("Data/ABOUT_00003.mp4")
offy = 25
offx = 40
frames = []
while True:
success, image = cap.read()
imgRGB = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = faceDetection.process(imgRGB)
if results.detections:
for lips in results.detections:
landmarks = lips.location_data.relative_keypoints
mouth = (int(landmarks[3].x * image.shape[1]), int(landmarks[3].y * image.shape[0]))
mouth = np.array(mouth)
x = mouth[0]
y = mouth[1]
frames.append(image[y+offy:y-offy,x-offx:x+offx,:])
cap.release()
for frame in frames:
cv2.imshow('frame', frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
它给出了“cv2.imshow('frame', frame) cv2.error: OpenCV(4.7.0) D: \opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:971: 错误: (-215:断言失败) size.width>0 && size.height>0 函数 'cv::imshow'
如果我尝试裁剪图像,则会显示相同的错误。请指导我。