openCVgui.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:OpenCV2 作者: SarathM1 项目源码 文件源码
def lipSegment(img):
    img = imutils.resize(img,width=300)
    img_copy = img.copy()

    landmarks = dlib_obj.get_landmarks(img)
    dlib_obj.get_face_mask(img_copy, landmarks)

    output_img = img-img_copy
    output_img = cv2.cvtColor(output_img,cv2.COLOR_BGR2GRAY)

    contours,hierarchy = cv2.findContours(output_img.copy(), cv2.cv.CV_RETR_EXTERNAL, cv2.cv.CV_CHAIN_APPROX_SIMPLE)  #cv2.findContours(image, mode, method
    cv2.drawContours(img, contours, -1, (0,255,0), 2,maxLevel=0)

    cnt = contours[0]
    ellipse = cv2.fitEllipse(cnt)
    (x,y),(MA,ma),angle = cv2.fitEllipse(cnt)


    a = ma/2
    b = MA/2


    eccentricity = sqrt(pow(a,2)-pow(b,2))
    eccentricity = round(eccentricity/a,2)

    font = cv2.FONT_HERSHEY_SIMPLEX

    cv2.putText(img,'Eccentr= '+str(round(eccentricity,3)),(10,350), font, 1,(255,0,0),2,16)

    if(eccentricity < 0.9):
        cv2.putText(img,'Commands = O',(10,300), font, 1,(0,0,255),2,16)
    else:
        cv2.putText(img,'Commands = E',(10,300), font, 1,(0,0,255),2,16)

    return img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号