6

I've found documentation regarding C ++, but not much with python.

The basic code to display in python is:

import numpy as np
import cv2

# Load an color image in grayscale
img = cv2.imread('messi.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

To show the image below. But how do I turn this

enter image description here

To look like this?

enter image description here

I also want to keep the size. So I've read some people saying to go "full screen". The only way I could think that might work is do "full screen, but then resize it? Not sure if that's a solution either though (also trying to find out how to do that as well... I'm brand new to OpenCV).

chitown88
  • 27,527
  • 4
  • 30
  • 59

2 Answers2

6

cap2 = cv2.VideoCapture(0)
cap2.set(3,320)
cap2.set(4,200)

ret2, image2 = cap2.read()
cv2.imshow('frame2',image2)

cv2.namedWindow('frame2',cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty('frame2', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

i have found a trick, just put

cv2.namedWindow('frame2',cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty('frame2', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

below

cv2.imshow('frame2',image2)

Here, what we are actualy doing is playing full video in smaller size. That's why there is no title bar and borders.

Rishabh Jhalani
  • 1,049
  • 13
  • 22
  • This is now outdated. – Vincent Casey Jun 01 '22 at 23:02
  • @VincentCasey Got some evidence to back that claim up? Some additional details wouldn't hurt either (what version, what HighGUI backend, what exactly is outdated) -- AFAICT full-screen mode is still supported in 4.6.0 with Win32 backend, I just reproduced it. – Dan Mašek Nov 28 '22 at 15:45
  • 1
    @DanMašek It's been a while since I've worked on this but if I can recall it's something with cv2.WND_PROP_FULLSCREEN or cv2.WINDOW_FULLSCREEN due to Windows changing something. Like I said though this was a while back and I can't remember exactly what the issue was so take my words with a grain of salt. – Vincent Casey Nov 28 '22 at 16:04
5

Did a little more looking around:

using these flags is how to do it with QT backend.

CV_GUI_NORMAL or CV_GUI_EXPANDED: CV_GUI_NORMAL is the old way to draw the window without statusbar and toolbar, whereas CV_GUI_EXPANDED is a new enhanced GUI.

unfortunetly, cv2.namedWindow('image', flags=cv2.CV_GUI_EXPANDED) does not work, even though I'm pretty sure I have QT backend (actually I'm positive I do).

After looking up help(cv2), I found similar flags WINDOW_GUI_EXPANDED and WINDOW_GUI_NORMAL. So use those.

img = cv2.imread('messi.jpg',0)

# Removes toolbar and status bar
cv2.namedWindow('image', flags=cv2.WINDOW_GUI_NORMAL)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

But still having trouble trying to remove the title bar.

chitown88
  • 27,527
  • 4
  • 30
  • 59
  • Did you find a way to remove the title bar? – takluiper Oct 03 '18 at 08:44
  • I did not. I ended up utilizing tKinter to get the display that I was trying to accomplish and was able to progress with that, so I abandoned looking further into displaying this way. – chitown88 Oct 03 '18 at 11:27