openCVgui.py 文件源码

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

项目:OpenCV2 作者: SarathM1 项目源码 文件源码
def main():
    print "\t\t########################################"
    print "\t\tOPTIMISED = ",cv2.useOptimized()," !!!!"
    print "\t\t########################################"

    while True:
        ret,img=cap.read()
        #img = cv2.medianBlur(img,3)    # 5 is a fairly small kernel size
        img = cv2.resize(img,None,fx=1.3,fy=1,interpolation = cv2.INTER_LINEAR)

        hand_box = [(0,50),(400,400)]
        head_box = [(500,50),(800,400)]
        cv2.rectangle(img,hand_box[0],hand_box[1],(255,255,255),2)
        cv2.rectangle(img,head_box[0],head_box[1],(50,50,50),2)

        head_frame = img[50:400,500:800]
        try:
            img[50:400,500:800] = lipSegment(head_frame)    
        except ValueError, e:
            #print e
            pass

        hand_frame = img[50:400,0:400]

        try:
            mask,counter,hull,(cx,cy),list_far,list_end = count_fingers(hand_frame)

            if(cv2.contourArea(hull)>3000) and list_far:
                cv2.drawContours(hand_frame,[hull],0,(0,255,0),1)
                [cv2.circle(hand_frame,far,5,[0,0,0],-1) for far in list_far]
                [cv2.circle(hand_frame,end,5,[150,150,150],-1) for end in list_end]
                cv2.putText(hand_frame,"Fingers = "+str(counter+1),(10,250),cv2.FONT_HERSHEY_SIMPLEX, 1,(0,0,255),2,1)

        except ZeroDivisionError, e:
            print "Count_fingers ZeroDivisionError: ",e
        except UnboundLocalError,e:
            print "Count_fingers UnboundLocalError: ",e



        cv2.imshow('Img',img)

        if cv2.waitKey(20)&0xff==ord('q'):
            cv2.imwrite('output.jpg',img)
            cv2.imwrite('Mask.jpg',mask)
            cv2.imwrite('hand_frame.jpg',hand_frame)
            break

    cap.release()
    cv2.destroyAllWindows()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号