@mihuzz

Как стекать словарь обернутый в список?

Как стекать словарь обернутый в список, словарь в котором меняются значения ?
Ниже print вроде все гут:
[{'image': 'image046.jpg', 'label': 'person', 'bbox': [252, 77, 162, 213]}]
[{'image': 'image047.jpg', 'label': 'person', 'bbox': [246, 73, 169, 225]}]
А когда я делаю append lista то у меня тупо все значения заполняются последнего изменения

myDataAnnotation = [{'image':'frame.jpg','label':'Miha', 'bbox': [0,0,0,0]}]
myDataAnnotationList = []
images = []
count = 0
while True:
    ret, frame = cap.read()
    if ret == True:
    # if not ret: # exit loop if there was problem to get frame to display
    #     break
        image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        # image = frame
        # print(image)
        # myDataAnnotation = {'image': 'frame.jpg', 'label': 'Miha', 'bbox': [0, 0, 0, 0]}
        # myDataAnnotationList = []

        count += 1
        result = detector.detect_faces(image)
        # print("result :", result)
        # print("type result :", type(result))
        for y in result:
            # print("Y :", y)
            for k, v in y.items():

                # print(k)
                # print(y['box'])
                # print(y['keypoints'])
                bbox = y['box']
                keypoints = y['keypoints']
                xmin = bbox[0]
                ymin = bbox[1]
                xmax = bbox[2]
                ymax = bbox[3]
                for q in myDataAnnotation:
                    q['bbox'][0] = bbox[0]
                    q['bbox'][1] = bbox[1]
                    q['bbox'][2] = bbox[2]
                    q['bbox'][3] = bbox[3]
                    #print(q['bbox'][0])
                    q['image'] = ('image{:03}.jpg'.format(count))

                # myDataAnnotation['bbox'][0] = bbox[0]
                # myDataAnnotation['bbox'][1] = bbox[1]
                # myDataAnnotation['bbox'][2] = bbox[2]
                # myDataAnnotation['bbox'][3] = bbox[3]
                # print("myDict 'bbox' 0:", myDataAnnotation[0]['bbox'][0])
                # print("myDict 'bbox' 1:", myDataAnnotation[0]['bbox'][1])
                # print("myDict 'bbox' 2:", myDataAnnotation[0]['bbox'][2])
                # print("myDict 'bbox' 3:", myDataAnnotation[0]['bbox'][3])
                #print("myDictAnnot :", myDataAnnotation)
                # print(xmin)

        #keypoints = result[0]['keypoints']

                cv2.rectangle(image,
                              (bbox[0], bbox[1]),
                              (bbox[0] + bbox[2], bbox[1] + bbox[3]),
                              (0, 155, 255),
                              2)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        #images.append(image)
        # myDataAnnotation['image'] = ('image{:03}.jpg'.format(count))
        #cv2.imwrite('image{:03}.jpg'.format(count), image)
        #myDataAnnotation['image'] = [f'img_{i}.jpg' for i in range(len(images))]
        #print("myDataAnnot :", myDataAnnotation[0]['image'])
        # for w, e in enumerate(myDataAnnotation):
        #     print(type(w))
        #     print(type(e))
        #     print("w:", w)
        #     print("e:", e)
        # myDataAnnotationList = []
        myDataAnnotationList.append(myDataAnnotation)
        print(myDataAnnotationList)
        #print("myDictAnnot :", myDataAnnotation)
        with open('damp.json', 'w') as f:
            json.dump(myDataAnnotationList, f, indent=2)
        # myDataAnnotationList.append(myDataAnnotation)
        # print("myDataAnnotationList :", myDataAnnotationList)
        cv2.imshow('frame', image)

Выводит один и тот же словарь последнего кадра
print(myDataAnnotationList):
[[{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}], [{'image': 'image048.jpg', 'label': 'Miha', 'bbox': [228, 112, 148, 196]}]]
  • Вопрос задан
  • 250 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы