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 (10802.4 * (1/30) * i)
k = round (30002.4 * (1/30) * i)
print (j, k)
img = oimg [0: 1080, j: k]
cv2.imwrite (f'img {i + 1: 04d} .png', img)

Answer # 1

Answer # 2
img = oimg [0: 1080, j: k]
Toimg = oimg [0: 1080, int (j): int (k)]
How about?
Related articles
 i don't know the cause of vba error 91
 python  i don't know how to deal with the error
 python  i don't know how to do css select in bs4
 c ++  i don't know the transition of abc180 e bit dp
 python  i don't know how to adapt the sample code
 java  i don't know the output of the instance
 i don't know the location of dlvdsosetupc in dbg
 c #  i don't know the answer to the exercise
 python  i don't know how to put out the sum of the matrix
 python  i don't know how to fix the type error
 i don't know how to write python
 python  i don't know how to use wait_for_motion () and wait_for_no_motion ()
 python  [beginner] i don't know how to write a bat file i want to run py
 xcode  i don't know where the csv is stored
 python  i don't understand the meaning of the code
 html  i don't know the calc () function
 apache  i don't see the centos tool web ui
 python  the link created with the collected path does not open
 how to count days of the week python
Related questions
 OpenCV + Unity + Python (integrations)
 python : How to add conditions in a DataFrame
 Sorting rows of generated matrix (Python)
 python : Block matrix 2x2 eigenvalue
 Please tell me how to use itertools.permutations in python. Please tell me how to make all the combinations.
 python : How do I get the minimum number of the 5 previous numbers in a vector?
 python : Declare numpy array with given size
 python : How to draw a function using matplotlib?
 python : Conversion from numpy to pytorch
 I want to output csv by combining the character string array and numerical array in Python
print (type (j))
As you can see,j
Alsok
I think it is also a float.The value may be an integer value, but the type is not an integer, so the error is that it cannot be used for slice.
Selfmade
round
It seems that is used, but it is prepared builtinround ()
OrAnd int should be converted.
(It's better to rename it because it suffers from the builtin round function and name)