5

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

Rishabh Jhalani
  • 1,049
  • 13
  • 22
  • Your question is hard to understand. What do you mean *"full screen but small"*? What is the backend... backend of what? What operating system are you using? Please add a picture of what it will look like. What methods have you tried? – Mark Setchell Dec 29 '18 at 12:49
  • I don't think it is possible from the openCV GUI interface. Maybe this GitHub can help: https://gist.github.com/goraj/a2916da98806e30423d27671cfee21b6 – J.D. Dec 29 '18 at 13:56
  • Eric shows quite a lot of the code and techniques you would want here... https://stackoverflow.com/a/41228386/2836621 – Mark Setchell Dec 29 '18 at 14:13

3 Answers3

4

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.
Rishabh Jhalani
  • 1,049
  • 13
  • 22
1

I know this is old post. But since I didn't find better/simpler answer elsewhere - I'll post my solution. Done entirely in cv2.

It can be done - it's just ridiculous way to do it. You start up in full screen mode, then move and resize your window. After that it is titlebarless and borderless. In my solution I used also TOPMOST property to lock stream preview on top of everything (I use it to monitor sick grandma while I work).

    stream_window = 'RPi3 IR cam'
    window_width = 240
    window_height = 180
    cv2.namedWindow(
        stream_window,
        flags=(cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_NORMAL | cv2.WINDOW_FREERATIO))
    cv2.setWindowProperty(stream_window, cv2.WND_PROP_TOPMOST, 1.0)
    cv2.setWindowProperty(stream_window, cv2.WND_PROP_FULLSCREEN, 1.0)
    cv2.resizeWindow(
        stream_window,
        window_width,
        window_height)
    cv2.moveWindow(
        stream_window,
        screen_width - window_width,
        screen_height - window_height - 40)

After that just call cv2.imshow with contents you need.

Cheers :)

0

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.

kocica
  • 6,412
  • 2
  • 14
  • 35