-1
I’m trying to treat a huge number of images with opencv
python
The vast majority will be despised, so I would like to capture the Warning messages from opencv to be able to treat/despise these images.
I’ve tried to warnings
, sys.stderr
but warnings keep popping up and I can’t capture/treat.
There are few images with warnigs. But want to treat.
If anyone can help me I’d appreciate it.
a small example :
import cv2
import warnings
warnings.filterwarnings("error")
try:
cv2.imread('/dados/dev/google/google/downloads/amazan/20.amazan.png')
print('Imagem lida')
except Exception as error_e:
print(f"Erro/Warning : {error_e}")
Upshot :
/usr/bin/python3.7 /data/dev/google/lab/test.py
libpng Warning: iCCP: known incorrect sRGB profile
libpng Warning: iCCP: cHRM Chunk does not match sRGB
Image read
These Warning are not handled by language. They are the result of applying a non-standard ICC profile. Then what you should do is remove the problematic ICC profile with a graphical editing software. If it’s a Linux environment use Imagemagick to post-process images because it fixes various bugs that graphics editors leave or ignore in images.
– Augusto Vasques
There are millions of images, just wanted to know which has this Warning to despise. so that do not arrive in the next phase still with Warning. It is an automatic process that will run in the background, without human interaction. But I already have more information to continue researching. Thank you very much. Thanks.
– Eduardo Xavier
Augusto did not understand why he voted in the closing. The question continued unanswered. Can you explain to me why?
– Eduardo Xavier
The answer is that these warnings are not handled by the language and you have to, outside the language, use a processing software to normalize the images. Concept beyond the scope of programming languages.
– Augusto Vasques
Do you mean that if I make a program that uses images, I should let these warnings appear to the end user? After all the images will not always be mine, someone can use it. I do not believe that there is no way to recognize this Warning. even if I don’t treat it. But letting go to the screen doesn’t make sense.
– Eduardo Xavier
Just take a look Google search how to delete libpng warnings. There is no possibility of deletion, that is a price to pay for free software. If you want more control write your own graphic library or modify libpng to suit your purposes.
– Augusto Vasques
I got help and the solution in the international stack overflow. I still don’t think it was reason to close my question, after all I found a solution within my code. but ... all right, I learned a little more. If you’re interested: https://stackoverflow.com/questions/59257111/how-to-identify-a-libpng-warning-in-python
– Eduardo Xavier
But the same thing was said here as the comments transcription: "These errors probably come from the C library, and nothing in the python layer; therefore, the use of warnings and sys.stderr will not be detected (as you experienced). The only thing that comes to mind right now is to redirect the STDERR process when your script is called. It’s probably not ideal for a script you want to provide to other users. - Gordon Bean 1 hour ago" .....
– Augusto Vasques
"You can try reading an image as direct binary (not decoding it as PNG) and look for the iCCPnela string. Ignore the file if present. - Mark Setchell 1 hour ago PNG files are very modular, so you can also edit that piece of the file and load it with Opencv. Try searching using only grepalguns files to see if it identifies the problematic and not many perfectly happy properly"
– Augusto Vasques
If you are dissatisfied with the closing of the question. Make a complaint on Stack Oerflow META
– Augusto Vasques