问题描述
我有一个 python 应用程序,我将字典输入到 for 循环中,在循环之后,我将该字典插入到元组中。在将 Dictionary 插入到 Tuple 之后,我给 Dictionary 一个 .clear(),用于循环的另一个循环,但是当使用 .clear() 时,Tuple 留下了一个空集合。 我已经尝试将 Dictionary 中的数据添加到辅助变量中,以避免这种行为,但在那之前并没有解决我的问题。 有谁知道如何从字典中删除数据而不影响元组中存储的数据?
def predictPeople(imageByte,listEpis):
image = UPLOAD_FOLDER+"/"+imageByte
dateTime = datetime.Now()
stringDate = dateTime.strftime("%d/%m/%Y,%H:%M:%s")
stringDate = stringDate.replace("/","").replace(":","").replace(",","")
detector = ObjectDetection()
detector.setModelTypeAsYOlov3()
detector.setModelPath(modelPeople)
detector.loadModel()
detectionList = []
detectionAllList = ()
resultFolder = pathImageResult + "/" + stringDate + ".jpg"
custom = detector.CustomObjects(person=True)
folders = None
detections = detector.detectCustomObjectsFromImage(custom_objects=custom,input_image=image,output_image_path=resultFolder,extract_detected_objects=True,minimum_percentage_probability=50)
if len(detections) > 0:
folder = resultFolder+"-objects"
obj = RecognitioCustonImage(folder)
#Bring up a list of folders with images
folders = obj.detectEpi()
peopleDetection = {}
imageDetectionPeople = {}
#Scrolls through a list of folders
for fold in folders:
#Lists images in a folder
detectionImages = os.listdir(os.path.join(fold))
#Scroll through the list of images in a folder
for peopleImage in detectionImages:
imagePath = fold+"/"+peopleImage
imageDetectionPeople.update({str(peopleImage):Convert(imagePath)})
auxImage = imageDetectionPeople
peopleDetection.update({"Pessoa":auxImage})
y = list(detectionAllList)
auxPeople = peopleDetection
y.append(auxPeople)
#Stores the list of images in another list
detectionAllList = tuple(y)
peopleDetection.clear()
imageDetectionPeople.clear()
return jsonify(detectionAllList)
代码调试 gif
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)