How to show image without title bar and border in opencv python

Viewed 5609

Show image like its shows in full screen but in small size. from backend we select the image size and we have to show this image without any title bar and border. only image will appear. i try lot of methods, but didn't get success. is there any way to do this ? if any body knows, please help, i stuck in this from many days

Operating System: Raspberry PI Language Using: Python 3

2 Answers

With the help of tkinter window/frame, we can show image or video without any border and title bar. what we have to do is, make tkinter window transparent. I am putting my code below, which shows webcam video without borders and title bar in any size.

import numpy as np
import cv2
from tkinter import *
#import tkinter as tk
from PIL import Image, ImageTk
import sys

window = Tk()  #Makes main window
window.overrideredirect(True)
window.wm_attributes("-topmost", True)
window.geometry("+600+200")
display1 = Label(window)
display1.grid(row=1, column=0, padx=0, pady=0)  #Display 1
cap = cv2.VideoCapture(0)

def show_frame():
    _, frame = cap.read()
    frame = cv2.resize(frame, (400,400))
    #frame = cv2.flip(frame, 1)
    cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
    img = Image.fromarray(cv2image)
    imgtk = ImageTk.PhotoImage(master = display1, image=img)
    display1.imgtk = imgtk #Shows frame for display 1
    display1.configure(image=imgtk)
    
    window.after(10, show_frame)

show_frame()
window.mainloop()

frame = cv2.resize(frame, (400,400)) this is use to resize our frame.

Windows where images are displayed in OpenCV are implemented in HighGUI module using either OpenGL or Qt. You can modify a bit what will be shown to the user (depends on system also), but i think what you're trying to achive is not possible in OpenCV.

Here is list of all flags you can use while creating new window/widget in OpenCV. Unfortunately there is no flag to hide title bar like it is in full-screen mode. Why? It's not important to OpenCV users. They are using imshow just to see the results, mainly for debugging purposes, so they don't need to remove title-bars.

What you can do? Link your program with Qt framework and display image using Qt directly, not throught the wrapper. This might be helpful.

Related