Quantcast
Viewing all articles
Browse latest Browse all 4971

Beginners • Re: warning message when reading .jpg file on RPi4b with cv2

I tried the jpegtran method. It (apparently) successfully converted the image and saved it as a new image. I can load the old and new images in Windows and they appear the same, so it appears the actual image was preserved. The file size for the converted image was significantly smaller (41KB original and 19KB converted).

When I ran the .py program to display it, though, I still get the same warning message.

My program:

Code:

#test GPIO program using interruptsimport RPi.GPIO as GPIOimport timeimport cv2state = 0#defines of input pin, output pin, and modeBUTTON_PIN = 16     # I/O header pin 36 ; GPIO16LED_PIN = 4         # I/O header pin 7 ; GPIO4GPIO.setmode(GPIO.BCM)#define function to respond to pin interrupt (define before calling)def button_callback(channel):    if GPIO.input(BUTTON_PIN) == GPIO.HIGH:        print("Button has been released")        GPIO.output(LED_PIN, False)    else:        print("Button has been pressed")        GPIO.output(LED_PIN, True)#set up the pin directions and register interrupt routine    GPIO.setup(BUTTON_PIN, GPIO.IN, GPIO.PUD_UP)GPIO.setup(LED_PIN, GPIO.OUT, GPIO.PUD_OFF, False)GPIO.add_event_detect(BUTTON_PIN,GPIO.BOTH,                      callback=button_callback,                      bouncetime=100)#loop to try to execute background ... bails if <ctrl>+Ctry:    while True:     # background operation goes here        if state == 0:            img_bgr = cv2.imread('egret_640_480.jpg')            img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)            cv2.imshow("Color", img_bgr)            cv2.imshow("Gray", img_gray)                        state = 1        else:            print("loop...")            time.sleep(1)            except KeyboardInterrupt:    GPIO.cleanup()    cv2.waitKey(0)    cv2.destroyAllWindows()
With the program as listed (launched from Geany), I get a window to pop up after a few seconds (presumably it takes a while to load the cv2), then the color image (only) is displayed. Then it goes into the background loop where I can push the pushbutton and get the LED to light correctly. I can repeat that as often as needed. When I hit <ctrl>+C to exit, the program stops and the gray image is displayed.

The following message is displayed in the window:
  • (python:1979): GLib-GObject-CRITICAL **: 08:25:36.804: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
    loop...
    loop...
    loop...
    loop...
    ^Clibpng warning: iCCP: known incorrect sRGB profile
    libpng warning: iCCP: known incorrect sRGB profile
    libpng warning: iCCP: known incorrect sRGB profile
    libpng warning: iCCP: known incorrect sRGB profile
Aside from the warning messages (which are nuisances but not show-stoppers), the Critical Error message is concerning. Again, it apparently doesn't stop the program from running but the gray image is not displayed until I stop the main loop program with <ctrl>+C.

As another note, I tried just launching the Python program from a terminal session. I get the same results but I don't get the critical error message.

????

Statistics: Posted by starfire151a — Tue Oct 22, 2024 2:53 pm



Viewing all articles
Browse latest Browse all 4971

Trending Articles