偵測知名人士
def celebrities(self, event = None):
self.Name = ""
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:
celebrities_response = client.recognize_celebrities(
Image=
{'Bytes': image.read()})
cele_jsonfile = "celebritiesoutput.json"
with open(cele_jsonfile, 'w') as fp:
json.dump(celebrities_response, fp)
for celebrity in celebrities_response['CelebrityFaces']:
for eachperson in celebrity['Face']['Landmarks']:
cv2.circle(imOut,
(int(width*eachperson['X']),
int(height*eachperson['Y'])),
1, self.color_1, -1)
cv2.rectangle(imOut,
(int(width*celebrity['Face']['BoundingBox']['Left']),
int(height*celebrity['Face']['BoundingBox']['Top'])),
(int(width*(celebrity['Face']['BoundingBox']['Left']+
celebrity['Face']['BoundingBox']['Width'])),
int(height*(celebrity['Face']['BoundingBox']['Top']+
celebrity['Face']['BoundingBox']['Height']))),
self.color_2,int(self.linesizespinbox.get()))
self.DisplaySceneMarkInfo.insert(tk.END,celebrity['Urls'])
self.DisplaySceneMarkInfo.insert(tk.END,celebrity['Name'])
self.Name = str(celebrity['Name'])
self.DisplaySceneMarkInfo.insert(tk.END,"\n")
self.open_webbrowser()
while True:
# 複製一份原始影像
#imOut = img.copy()
# 顯示結果
cv2.imshow("Output", imOut)
# 讀取使用者所按下的鍵
k = cv2.waitKey(0) & 0xFF
# 若按下 q 鍵,則離開
if k == 113:
break
# 關閉圖形顯示視窗
cv2.destroyAllWindows()
打開瀏覽器搜尋
def open_webbrowser(self):
import webbrowser
from urllib.parse import quote
new = 2 # not really necessary, may be default on most modern browsers
base_url = "http://www.google.com/?#q="
#query = input("Please enter your search query: ")
final_url = base_url + quote(self.Name)
webbrowser.open(final_url, new=new)