Home>
I'm trying to reverse the image loaded on tkinter
Problem i am experiencingAfter reversing the image, after converting from BGR → RGB → PIL format → ImageTk format to display with tkinter, the transparent part is no longer transparent
Applicable source codeimport tkinter
import cv2
from PIL import Image, ImageTk
root = tkinter.Tk ()
image_bgr = cv2.imread ('Image.png', cv2.IMREAD_UNCHANGED)
yAxis = cv2.flip (image_bgr, 1) #where image flipping with OpenCV
cv2.imwrite ('yAxis-reflect.png', yAxis) #Output image for confirmation-transparent parts are still transparent
image_rgb = cv2.cvtColor (yAxis, cv2.COLOR_BGR2RGB) # Since imread is BGR, convert to RGB
image_pil = Image.fromarray (image_rgb) # Convert from RGB to PIL format
image_tk = ImageTk.PhotoImage (image_pil) # Convert to ImageTk format
canvas = tkinter.Canvas (root, bg = "white", width = 400, height = 350) # Create Canvas
canvas.pack ()
canvas.create_image (0, 0, image = image_tk, anchor = 'nw') # ImageTk image layout
root.mainloop ()
Because the transparent part is no longer transparent after image inversion
I tried to put Image.putalpha () that transmits the image with PIL between various places, but I was not detailed about PIL, so it was useless
Refer to this page for how to invert the image ・ Display the image edited with OpenCV with tkinter
How to flip images with OpenCV
http://peaceandhilightandpython.hatenablog.com/entry/2016/01/08/000857
How to display OpenCV images on tkinter
https://qiita.com/[email protected]/items/bc56441e80b3ccd5b2a4
-
Answer # 1
Related articles
- pytorch read image data into opencv format example
- Python uses opencv to convert the image format and base64
- format the image learned by cnn with opencv
- python 3x - i want to make one image transparent when overlaying two images
- Python ecosystem image format conversion problem (recommended)
- opencv implement image color space conversion
- VS2010 + Opencv + MFC read image and video display in Picture control
- opencv example code to adjust image brightness contrast
- PHP simple image format conversion (jpg to png, gif to png, etc)
- Python uses Opencv to implement image feature detection and matching
- Implementation of Python OpenCV image specified region cropping
- Opencv video to image sequence implementation
- Analysis of python opencv calculation image similarity process
- Find image differences using OpenCV and Python
- Python opencv sample code for gif image decomposition
- Opencv resize image to achieve square size
- Implementation method of various image format conversion in torch
- Python converts OpenCV format and PILImage format
- How to read image format in a file
- Use python to convert dcm format image to jpg format
Related questions
- format the image learned by cnn with opencv
- python - i want to combine split images
- opencv cv2imread() error
- python - i would like to know why the capacity changes when i load an image and just save it
- python - pedestrian age group discrimination using opencv
- i can't install opencv-python on the sakura rental server
- python - i want to divide the image into grids and find the hsv value
- python - i want to find the average hsv value for each divided image
- [opencv] i want to convert a black and white image that is a binary image to a specific color
- python - 4 resolved title
image_rgb = cv2.cvtColor (yAxis, cv2.COLOR_BGR2RGB)
image_rgb = cv2.cvtColor (yAxis, cv2.COLOR_BGR2RGBA)
Yes, Q71 who commented! m (_ _) m