如何解决可执行文件在 Python 中给出“无法执行”脚本
我使用 ageitgey repo 作为实现 face recognition python 库的参考。这段代码运行得很好,但是在制作可执行文件时,它的抛出错误为无法执行脚本 MainFR。
MainFR.py 是我的主要 python 文件。
这是我正在使用的代码。
import json
import os
import cv2
import face_recognition
import pandas as pd
import numpy as np
from PIL import Image
from io import BytesIO
from simple_salesforce import Salesforce,SalesforceLogin,SFType
----------
code to connect salesforce and fetching images
----------
# In lstRecords1 I am fetching images from 3rd party system(salesforce) and the data is coming
attachs = pd.DataFrame(lstRecords1)
insname = sf.sf_instance
folpath = '.\Attachments Download'
for row in attachs.iterrows():
recid = row[1]['ParentId']
fname = row[1]['Name']
atturl = row[1]['Body']
if not os.path.exists(os.path.join(folpath)):
os.mkdir(os.path.join(folpath))
request = sf.session.get('https://{0}{1}'.format(insname,atturl),headers = sf.headers)
with open(os.path.join(folpath,fname),'wb') as f:
f.write(request.content)
#f.close()
video_capture = cv2.VideoCapture(0)
obama_photo = face_recognition.load_image_file(os.path.abspath("Attachments Download/Obama.jpg"))
obama_face_encoding = face_recognition.face_encodings(Obama_photo)[0]
arnie_image = face_recognition.load_image_file(os.path.abspath("Attachments Download/arnie1.jpg"))
arnie_face_encoding = face_recognition.face_encodings(arnie_image)[0]
known_face_encodings = [
arnie_face_encoding,Obama_face_encoding
]
known_face_names = [
"Arnold","Obama"
]
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True
while True:
# Grab a single frame of video
ret,frame = video_capture.read()
# Resize frame of video to 1/4 size for faster face recognition processing
#small_frame = cv2.resize(frame,(0,0),fx=0.25,fy=0.25)
super_small_frame = cv2.resize(frame,fx=0.12,fy=0.12)
# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
#rgb_small_frame = small_frame[:,:,::-1]
rgb_small_frame = super_small_frame[:,::-1]
# Only process every other frame of video to save time
if process_this_frame:
# Find all the faces and face encodings in the current frame of video
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame,face_locations)
face_names = []
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(known_face_encodings,face_encoding)
name = "Unknown"
# # If a match was found in known_face_encodings,just use the first one.
if True in matches:
first_match_index = matches.index(True)
name = known_face_names[first_match_index]
print('result is :::',name)
#os._exit(0)
# Or instead,use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(known_face_encodings,face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
face_names.append(name)
process_this_frame = not process_this_frame
# Display the results
for (top,right,bottom,left),name in zip(face_locations,face_names):
# Scale back up face locations since the frame we detected in was scaled to 1/4 size
top *= 4
right *= 4
bottom *= 4
left *= 4
# Draw a box around the face
cv2.rectangle(frame,(left,top),(right,bottom),255),2)
# Draw a label with a name below the face
cv2.rectangle(frame,bottom - 35),cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame,name,(left + 6,bottom - 6),font,1.0,(255,255,1)
# Display the resulting image
cv2.imshow('Video',frame)
# Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()
谁能建议我在这里做什么?我被困在这将近 2 周
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。