列表和已建立的类有问题吗?

时间:2019-05-09 02:36:22

标签: python-3.x

我建立了一个名为“帧”的类,该类用于组合视频帧的数量和帧之间的差异。然后将Frame附加到称为“ frames”的列表中。然后,我将“框架”传递到在“框架”类中定义的函数中,但是列表的长度为零。列表“帧”的长度是496


class Frame:


    def __init__(self, id, diff):
        self.id = id
        self.diff = diff

    def __lt__(self, other):
        if self.id == other.id:
            return self.id < other.id
        return self.id < other.id

    def __gt__(self, other):
        return other.__lt__(self)

    def __eq__(self, other):
        return self.id == other.id and self.id == other.id

    def __ne__(self, other):
        return not self.__eq__(other)

    def second_find_diff_max(self, list_frames=[], start_no=0):
        sus_max_frame = []  # 可疑的镜头帧,以M为值
        window_frame = []
        window_size = 10
        m_suddenJudge = 1
        m_MinLengthOfShot = 8

        # print(list_frames[1].id)
        # print(list_frames[1].diff)

        length = len(list_frames)
        id_list = range(0, length)
...

以下是main.py

"""

if __name__ == "__main__":
    # dataload
    videopath = './test.mp4'
    # videopath = 'D:/MMlab/never_say_die.mp4'
    # Directory to store the processed frames
    dir = './frames'
    # smoothing window size
    len_window = int(50)

    print("target video :" + videopath)
    print("frame save directory: " + dir)
    # load video and compute diff between frames
    cap = cv2.VideoCapture(str(videopath))
    curr_frame = None
    prev_frame = None
    frame_diffs = []
    frames = []
    success, frame = cap.read()
    i = 0
    while (success):
        luv = cv2.cvtColor(frame, cv2.COLOR_BGR2LUV)
        curr_frame = luv
        if curr_frame is not None and prev_frame is not None:
            # logic here
            diff = cv2.absdiff(curr_frame, prev_frame)
            diff_sum = np.sum(diff)
            diff_sum_mean = diff_sum / (diff.shape[0] * diff.shape[1])
            frame_diffs.append(diff_sum_mean)
            print(diff_sum_mean)
            frame = Frame(i, diff_sum_mean)
            frames.append(frame)
        elif curr_frame is not None and prev_frame is None:
            diff_sum_mean = 0
            frame_diffs.append(diff_sum_mean)
            print(diff_sum_mean)
            frame = Frame(i, diff_sum_mean)
            frames.append(frame)

        prev_frame = curr_frame
        i = i + 1
        success, frame = cap.read()
    cap.release()
    print('total number = ', i)
    # print(frames[0].diff)
    # print(frames[1].id)
    # print('frames type ', type(frames))
    # print('frame type ', type(frame))
    # print(len(frames))
    frame_return = Frame.second_find_diff_max(frames)
    print(frame_return)
    #print(frame_return.id)

0 个答案:

没有答案