Detailed description of the error
When using the imwrite function of OpenCV to save pictures, report CV2. Error: opencv (4.2.0) C:: <projects/opencv Python/opencv/modules/imgcodecs/SRC/loadsave cpp:715 : error: (-215:Assertion failed) !_ img.empty() in function ‘cv::imwrite’
Error analysis
Use clip
to segment the image. The code is as follows
clip_img = img[top:(top+height),left:(left+width),:]
terms of settlement
img
is not none
, through clip_ IMG is none
can’t be judged. It can be judged by size
attribute. The code is as follows
if clip_img.size == 0:#Do not use imwriter for this case
In addition to not processing, there is another solution, check whether the values of the divided rows and columns are legal
, legal conditions:
The minimum value of segmentation cannot be less than 0, the maximum value of segmentation cannot be greater than the width and height of the picture, and the maximum value of segmentation must be greater than the minimum value of segmentation
Similar Posts:
- Ffmpeg scaling — the solution of “width / height not divisible by 2”
- [Solved] CDH6.3.2 Hive on spark Error: is running beyond physical memory limits
- Tuning and setting of memory and CPU on yarn cluster
- [Solved] echart Error: Can’t get dom width or height
- tf.nn.top_k(input, k, name=None) & tf.nn.in_top_k(predictions, targets, k, name=None)
- Tomcat Error: Invalid maximum heap size
- eclipse.ini/myeclipse.ini -Xms,-Xmx,-PerSize
- [record a problem] Linux + opencv + cuvid decodes 1080p video. When using CUDA kernel function, it will crash
- Nginx an upstream response is buffered to a temporary file,nginx502 Error
- [Solved] OpenCV 4 (C++) Error: “error: ‘CV_FOURCC’ was not declared in this scope”