我正在做一个项目,我必须从人体的热图像中检测鼻孔,以检测呼吸时间,利用它我可以检测呼吸频率。我已经完成了分割,但我无法将鼻孔部分提取为单独的图像。我已附上代码和下图:
#import the required packages
from imutils import face_utils
import argparse
import dlib
import imutils
import cv2
import numpy as np
#passing the shape predictor and image thro' argparse
ap=argparse.ArgumentParser()
ap.add_argument("-p", "--shapepredictor", required=True, help="path to find rquired facial landmark")
ap.add_argument("-img", "--image", required=True, help="path to input image")
args=vars(ap.parse_args())
detector=dlib.get_frontal_face_detector()
predictor=dlib.shape_predictor(args["shapepredictor"])
while True:
frame=cv2.imread(args["image"])
frame=imutils.resize(frame,width=500)
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
rect=detector(gray, 0)
#detecting the face and then the nose
for i in rect:
x,y,w,h=face_utils.rect_to_bb(i)
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
shape=predictor(gray,i)
shape=face_utils.shape_to_np(shape)
for nx,ny in shape:
cv2.circle(frame,(nx,ny),3,(255,0,0),-1)
cv2.imshow("Frame",frame)
key=cv2.waitKey(0) & 0xff
if key==27:
break
cv2.destroyAllWindows()
既然我已经检测到鼻孔部分,我该如何将其提取为单独的图像?谁能帮帮我吗
对图像进行子集的方法是在帧变量(2d np.array)上建立索引
例如:
为了扩展我的答案,这里有一个最小的功能示例,它是从url加载的图像运行的图像子集,但使用cv2包
相关问题 更多 >
编程相关推荐