Home>

I'm thinking of cropping an image that is 3000 x 1080.
However, I get an error and I don't understand. Help me.
The content of the error is
1080.0 3000.0
Traceback (most recent call last):
File "C: \ Users \ Desktop \ trimming.py", line 13, in
img = oimg [0: 1080, j: k]
TypeError: slice indices must be integers or None or have anindexmethod
is.
I thought it was due to the decimal point, but I didn't understand.

import cv2
import matplotlib.pyplot as plt
import numpy as np
import math
round = lambda x: (x * 2 + 1) // 2
oimg = cv2.imread ('grid.png')
for i in range (10):
  j = round (1080-2.4 * (1/30) * i)
  k = round (3000-2.4 * (1/30) * i)
  print (j, k)
  img = oimg [0: 1080, j: k]
  cv2.imwrite (f'img {i + 1: 04d} .png', img)