Capture python libpng Warning

Asked

Viewed 124 times

-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.

  • 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.

  • Augusto did not understand why he voted in the closing. The question continued unanswered. Can you explain to me why?

  • 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.

  • 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.

  • 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.

  • 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

  • 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" .....

  • "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"

  • If you are dissatisfied with the closing of the question. Make a complaint on Stack Oerflow META

Show 5 more comments

1 answer

1

As I said before, warnings are not mistakes, the images are probably even having problems with the color profile, but this does not directly (usually) affect what you will do with the image, and as I said, you can try using the pngcrush with command line in the whole folder pictures (if it is all PNG facts with problem), example:

find -f . png | while read filename; do pngcrush -ow -rem allb -reduce "{$filename}"; done

Now delete the error will not solve the problem, agree?

I want to make it clear that these warnings are not generated "totally" by openCV, but by libpng, so it may not even be a Warning at the level of the script itself, might just be a normal libpng output and really you won’t have any control over it and deleting the warnings won’t be the same thing as using one try/except to get him on an exception.

  • William, I am really coming to the conclusion that I will not have control over this very thing and you are right, suppressing is not the solution. What I really wanted was to identify these warnings within my program, but I couldn’t. But thank you very much.

  • Not demeaning your command but with imagemagick is easier just do mogrify *.png that it fixes all files in a folder.

  • 1

    @Augustovasques if he’s installed and so on mogrify and actually mapping "RECURSIVELY" would help, but they’re different programs, as far as it goes. ps: the command find and the use of the pipe (|) or of while are Unix-like system commands, precisely to work with files, either recursively or at a level combining with other programs, which is often a hand in the wheel :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.