Error: OpenCV(3.4.2) error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'cv::arithm_op'

Hi everyone
I am currently working on keyframe extraction from videos.

Code :

import torch
from import Dataset
from PIL import Image
import numpy as np
import cv2

class makeDataset(Dataset):
    def __init__(self, dataset, labels, spatial_transform, seqLen=20):
        self.spatial_transform = spatial_transform
        self.images = dataset
        self.labels = labels
        self.seqLen = seqLen

    def __len__(self):
        return len(self.images)

    def __getitem__(self, idx):
        vid_name = self.images[idx]
        label = self.labels[idx]
        inpSeq = []
        ret, prev_frame =
        p_frame_thresh = 20
            # Extract images
            ret, curr_frame =
            diff = cv2.absdiff(curr_frame, prev_frame)
            non_zero_count = np.count_nonzero(diff)
            if non_zero_count > p_frame_thresh:
            prev_frame = curr_frame
        print (count)
        inpSeq = torch.stack(inpSeq, 0)
        return inpSeq, label

what is the problem here, I don’t understand this error? can any one guide me please :slight_smile:

The two frames in video not having the same size.

diff = cv2.absdiff(curr_frame, prev_frame)

this operation only performs when the two frames having same size.

I am also having the same problem… How do you fix it ? I am new to Python and learning now… I hope that there is a way to make the images of same sizes using code…