Linked Questions

Popular Questions

I have a problem with openCV(4.6.0) and Python with linux 22.04.

I have a panoramic picture and try to create a video out of it that pans over the image. The first 100 pixel it works just fine but then a segfault exception is thrown by openCV. The image itself is more than 4000 pixel wide. I have no idea why the first frames work just fine. You can find the img here.

import numpy as np
import cv2

imgPath = './../pan/pan_01/pan_01_B_small.png'
numframes = fps*seconds

img = cv2.imread(imgPath, 1)
print("Image Size:", img.shape)
shiftPerFrame = (img.shape[1] - width) / numframes
print("Shift/Frame: ", shiftPerFrame)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, fps, (width,height))

for i in range(1,numframes):   # init frames
    x = int(i * shiftPerFrame)
    crop_img = img[0:height, x:x+width]
    print("Frame: ", i, " Position x:", x, " to ", x+width, "size: ", crop_img.shape)
    #cv2.imwrite("data/img" + str(i) + ".jpg", crop_img)

It isn't a problem to export the cropped image again as a new jpg.

I played a little with the shifting parameter. I found out that the problem is not the xth frame but somehow the pixel position. I also tried to import the image as a jpg or png. I also tryed several codecs. Each with the same error.

I am happy about any ideas and help.

Related Questions