iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 16
0
自我挑戰組

軟體開發隨筆雜記--試著解決問題系列 第 16

[Python][OpenCV][AWS]Rekognition(1)face_rekognition

UI
https://ithelp.ithome.com.tw/upload/images/20210114/20119608yG6ItrEQ5e.jpg
https://ithelp.ithome.com.tw/upload/images/20210114/20119608dlhVKW09vV.jpg

Face Rekognition

https://ithelp.ithome.com.tw/upload/images/20201001/20119608fT70fF22Sw.jpg

    def face_rekognition(self,event = None):
        client=boto3.client('rekognition')
        img = cv2.imread(self.imageFile)
        img_PIL = Image.open(self.imageFile)
        width, height = img_PIL.size
        with open(self.imageFile, 'rb') as image:
            faces_response = client.detect_faces(Image=
                                                 {'Bytes': image.read()},
                                                           Attributes=['ALL'])
        face_jsonfile = "faceoutput.json"
        with open(face_jsonfile, 'w') as fp:
            json.dump(faces_response, fp)
        imOut = img.copy()
        for faceDetail in faces_response['FaceDetails']:
            cv2.rectangle(imOut,
                              (int(width*faceDetail['BoundingBox']['Left']),
                               int(height*faceDetail['BoundingBox']['Top'])),
                               (int(width*(faceDetail['BoundingBox']['Left']+
                                faceDetail['BoundingBox']['Width'])),
                               int(height*(faceDetail['BoundingBox']['Top']+
                               faceDetail['BoundingBox']['Height']))),
                              self.color_1,int(self.linesizespinbox.get()))
            for eachperson in faceDetail['Landmarks']:
                cv2.circle(imOut, 
                           (int(width*eachperson['X']), 
                            int(height*eachperson['Y'])),
                            int(self.linesizespinbox.get()),
                            self.color_2, 
                            -1)

        while True:
            cv2.imshow("Output", imOut)
            k = cv2.waitKey(0) & 0xFF
            if k == 113:
                break
        cv2.destroyAllWindows()

Compare face Rekognition

https://ithelp.ithome.com.tw/upload/images/20210114/20119608CafJ77c2u0.jpg
https://ithelp.ithome.com.tw/upload/images/20210114/201196089t5kQCh8ql.jpghttps://ithelp.ithome.com.tw/upload/images/20210114/20119608PKNPoolp9Y.jpghttps://ithelp.ithome.com.tw/upload/images/20210114/20119608ZaeOQGmDDS.jpg


上一篇
[Python][OpenCV]Selective Search
下一篇
[Python][OpenCV][AWS] Rekognition(2)celibrities
系列文
軟體開發隨筆雜記--試著解決問題33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言