Abnormal interpretation
When using OpenCV to write code, there will be typeerror: integer argument expected, get float error
The error is a type error. For example, the following code will report an error
img = cv.imread('10.jpg', 1)
rows, cols, channels = img.shape
M = np.float32([[1, 0, 100], [0, 1, 50]])
res = cv.warpAffine(img, M, (cols*0.5, rows*0.5))
cv.imshow("img", res)
cv.waitKey()
The error location is shown in the figure below, where the value of int
type is required, but after cols * 0.5
operation, the float
type appears
Exception resolution
Type cast
res = cv.warpAffine(img, M, (int(cols*0.5), int(rows*0.5)))
Appendix
This series of articles is only for recording the bugs encountered in the process of Python daily development and providing them to students as reference data and solutions. It belongs to the recording blog, and readers who are destined to see it hope to solve your problems
Error prompt template can be compared with your error
Traceback (most recent call last):
File "e:/crawl100/opencv_ppt/10day.py", line 7, in <module>
res = cv.warpAffine(img, M, (cols*0.5, rows*0.5))
TypeError: integer argument expected, got float
This article shares synchronously on the blog “dream eraser” (CSDN).
Similar Posts:
- [record a problem] Linux + opencv + cuvid decodes 1080p video. When using CUDA kernel function, it will crash
- Python OpenCV BUG: all the input arrays must have same number of dimensions
- Java call opencv face recognition error insufficient out of memory
- Tensorflow gradients TypeError: Fetch argument None has invalid type
- [Solved] Mybatis error: attempted to return null from a method with a primitive return type (int)
- Android ADT tool Updated Error: TypeError: argument of type ‘NoneType’ is not iterable
- Python bug problems and solutions sorted out in recent days
- Python TypeError: not all arguments converted during string formatting
- How to Solve R Error: Can’t bind data because some arguments have the same name (The R Programming Language)
- Python calculator error: can’t multiply sequence by non-int of type ‘float’