When using Python to process an image, it may involve the addition and subtraction between the pixel values of two images. Here, it should be noted that the pixel value of the image is of ubyte type, and the data range of ubyte type is 0-255. If the operation results in a negative value or exceeds 255, an exception will be thrown. Let’s take a look at an example of the exception
from PIL import Image import numpy as np image1 = np.array(Image.open("1.jpg")) image2 = np.array(Image.open("2.jpg")) # Exception statement temp = image1[1, 1] - image2[1, 1] # Overflow if this is a negative value # The correct way to write temp = int(image1[1, 1]) - int(image2[1, 1]) # force to integer and then calculate without overflowing
The above code is the exception runtimewarning: overflow accounted in ubyte_ Scalars of the reasons and solutions, I hope to help friends who encounter this problem.
Read More:
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00
- How to Fix pandas.errors.ParserError Error tokenizing data C error Buffer overflow caught
- Python+OpenCV: How to Use Background Subtraction Methods
- [Solved] ValueError: only one element tensors can be converted to Python scalars
- Python3.7 Capture exception error: Too broad exception clause
- How to Fix Errors encountered in executing Python scripts with command line parameters
- python2.7 ExcelWriter error Exception caught in workbook destructor. Explicit close() may be require
- [Solved] ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memor
- python3 Execute except Exception, e Error [How to Solve]
- ModuleNotFoundError: No module named ‘tensorflow.python’ And the pits encountered after installation
- RuntimeError: CUDA error: an illegal memory access was encountered
- When sending HTTP request, python encountered: error 54, ‘connection reset by peer’ solution
- [Solved] RuntimeError (note: full exception trace is shown but execution is paused at: <module>)
- Flash cli encountered a keyerror “migrate” [How to Solve]
- [Solved] Selenium error: staleelementreferenceexception exception
- Python: Django exception when executing migrate operation: django.db.utils.OperationalError: (1051, “Unknown table’xxx’”)
- Python: How to Use try exception to Display Abnormal Error Information
- Python syntax error except exception, e: ^ syntax error: invalid syntax
- Opencv Python realizes the paint filling function in PS, one click filling color and the possible reasons for opencv’s frequent errors
- Implementation of Kalman Filter in Python