iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 19
0
自我挑戰組

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

[Python][OpenCV][AWS] Rekognition(4)text_rekognition

  • 分享至 

  • xImage
  •  

https://ithelp.ithome.com.tw/upload/images/20201004/20119608Iy3ugvmXSR.jpg

    def text_rekognition(self, event = None):
        client=boto3.client('rekognition')
        img = cv2.imread(self.imageFile)
        imOut = img
        img_PIL = Image.open(self.imageFile)
        width, height = img_PIL.size
        with open(self.imageFile, 'rb') as image:
            text_response = client.detect_text(Image={'Bytes': image.read()})
            
        text_jsonfile = "textoutput.json"
        with open(text_jsonfile, 'w') as fp:
            json.dump(text_response, fp)

        #i = 0
        for text in text_response['TextDetections']:
            #Rectangle The text BoundingBox       
            cv2.rectangle(imOut,
            (int(width*text['Geometry']['BoundingBox']['Left']),
              int(height*text['Geometry']['BoundingBox']['Top'])),
             (int(width*(text['Geometry']['BoundingBox']['Left']+
              text['Geometry']['BoundingBox']['Width'])),
             int(height*(text['Geometry']['BoundingBox']['Top']+
             text['Geometry']['BoundingBox']['Height']))),
             self.color_1,
            int(self.linesizespinbox.get()))
            #print the text
            cv2.putText(imOut,
                        text['DetectedText'],
                        (int(width*text['Geometry']['BoundingBox']['Left']),
                         int(height*text['Geometry']['BoundingBox']['Top'])),
                         self.fontcv2Var.get(),
                         int(self.fontsizespinbox.get()),
                         self.color_2,
                         int(self.linesizespinbox.get()), 
                         self.fontlinetypecv2Var.get())
            self.DisplaySceneMarkInfo.insert(tk.END,text['DetectedText']+'\n')

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


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

尚未有邦友留言

立即登入留言