Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6392 Discussions

openCV 4.5.3 in openVINO 2021.4.689 : Window name issues not present in earlier versions

KArzo
Novice
2,551 Views

Ported our application to Ubuntu 20.04 with latest openVINO

- after clicking 'X' button it throws deprecation warning and one warning related to not seeing window with the given name, but it is being set. 

- when calling getWindowProperty, another exception and warning can't find window with name 

# check if the window is visible, this means the user hasn't closed
# the window via the X button
prop_val = cv2.getWindowProperty(devControl.window_name, cv2.WND_PROP_ASPECT_RATIO)
if (prop_val < 0.0):
devControl.end_flag.value = 1
controller.reset()
return

- screen full size mode does not work. stays at actual size

if normal_mode:
cv2.namedWindow(CV_WINDOW_NAME)
else:
cv2.namedWindow(CV_WINDOW_NAME, cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(CV_WINDOW_NAME,cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
logo = cv2.imread(KAMPER_LOGO_FILE)
logo_img = logo
cv2.imshow(CV_WINDOW_NAME, logo_img)
cv2.waitKey(100)

 

0 Kudos
13 Replies
Peh_Intel
Moderator
2,514 Views

Hi KArzo,


Thanks for reaching out to us.


I am unable to proceed by running your shared codes as the name 'devControl' is not defined.


We would like to request your script for us to help running on earlier OpenVINO version which supported in Ubuntu 18.04.


On a separate note, I found a disclaimer that your proposed way to check the window may only work with OpenCV 3.x. (References: Example 4). You may also try checking the window by using cv2.WND_PROP_VISIBLE.


Regarding the full screen, there is no issue in the aspect of just looking through your shared codes. Perhaps you can try exchange the codes which is running full screen in normal mode and observe the behavior.



Regards,

Peh


0 Kudos
Kahren
Beginner
2,429 Views

Hi Peh,

Pretty sure I had provided additional information a couple of days ago but somehow it did not get saved. Anyhow, here' s the info:

also attached is simplified code to show the issue.

 

Ubuntu Version Python Version CV2 Version Fullscreen issue Window name issue
16.04 3.5 4.3.0-openvino-2020.3.0 No No
18.04 3.6 4.3.0-openvino-2020.3.0 Yes No
20.04 3.8 4.5.3-openvino Yes Yes
0 Kudos
KArzo
Novice
2,364 Views

Hi Peh, 

Here's more info for you and thank you for your help thus far!  also attached is a cleaner code for you to run.

Ubuntu Version Python Version CV2 Version Fullscreen issue Window name issue
16.04 3.5 4.3.0-openvino-2020.3.0 No No
18.04 3.6 4.3.0-openvino-2020.3.0 Yes No
20.04 3.8 4.5.3-openvino Yes Yes
0 Kudos
Peh_Intel
Moderator
2,442 Views

Hi KArzo,

 

Thank you for your question. If you need any additional information from Intel, please submit a new question as this thread is no longer being monitored.

 

 

Regards,

Peh

0 Kudos
Peh_Intel
Moderator
2,392 Views

Hi KArzo,

 

Thanks for sharing your simplified code to duplicate the issue.

 

I tested your codes on Ubuntu 20.04 with OpenCV 4.5.3-openvino from OpenVINO™ 2021.4.689 and also OpenCV 4.2.0 installed from the Ubuntu Repository (sudo apt install libopencv-dev python3-opencv). Both OpenCV versions results in the same output. In addition, you can compare the changes with OpenCV 4.5.3-openvino and OpenCV 4.5.3 as documentation for OpenCV 4.5.3 is available.

 

Based on your codes, I get two different undesired outputs shown in the pictures below.

 

If setting “NORMAL_MODE = False”, the window outputs in full screen but not the image and the name of the window is also disappeared.

cv2.namedWindow(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN)

cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

namedWindow(cv2.WND_PROP_FULLSCREEN).PNG

 

If setting “NORMAL_MODE = True”, the window does not have the “Maximize” button to change the window to full screen.

cv2.namedWindow(WINDOW_NAME, cv2.WND_PROP_AUTOSIZE)

cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_AUTOSIZE, cv2.WINDOW_NORMAL)

namedWindow(cv2.WND_PROP_AUTOSIZE).PNG

 

Do these two outputs are the same as you mentioned as full screen issue and window name issue?

 

On a separate note, I only able to get the desired output in normal mode with the codes below.

namedWindow(cv2.WINDOW_NORMAL).PNG

setWindowProperty(cv2.WND_PROP_AUTOSIZE).PNG

cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)

cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_NORMAL)

 

 

Regards,

Peh

 

0 Kudos
SergeyVasilyan
Beginner
2,335 Views

Hello all,

I have the similar issues on my side, i.e. application name is not being set properly (it is always being set to 'Python3', please see attached image below) and full screen mode is not scaling the image to fill the whole screen, instead it fills empty space with grey color. These issues were not reproducible in earlier builds.

issue.png

Tried the following approaches to fix the issues:

  • used 'cv2.setWindowTitle' method but it does not work on my Ubuntu 20.04,
  • manipulated with window property flags, but the only change was bringing back 'maximize' button which is not required.

The example that was attached in this thread shows exactly what issues I have.

Please clarify whether the same issues are reproducible on your side.
If so, would you please share fixes to:

  • set application name properly,
  • fix issues with full screen mode.

Regards,
Sergey

0 Kudos
Peh_Intel
Moderator
2,256 Views

Hi Sergey,


I also got these two issues on my side. As such, I will channel to our development team for further investigate in fixing these issues.


In a meanwhile, regarding the full screen issue, I found that when adding resizeWindow function, the output is expanded and fitted to the full screen. However, there is still some empty space with grey colour. From my understanding, in full screen mode, the actual image size is expanded to the maximum by maintaining the same ratio of height and width. Hence, in this way, the image cannot perfectly fit to the full screen (rectangle shaped) and hence the rest of the space is filled with grey colour. I also need the clarification from our developers regarding this thought.


I will update you at the earliest once I get any update or feedback from them.


import cv2

img = cv2.imread(image.jpg, 1)

cv2.namedWindow("test", cv2.WND_PROP_FULLSCREEN)

cv2.setWindowProperty("test", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

cv2.resizeWindow("test",1,1)

cv2.imshow("test", img)

cv2.waitKey()

 

 

Regards,

Peh


0 Kudos
SergeyVasilyan
Beginner
2,232 Views

Hi Peh,

Thanks for your feedback.

Resizing of the image will decrease the application performance as I am using camera stream. So this approach is not preferable for now.

I will wait for the response from you.

Regards,
Sergey

0 Kudos
Maksim_S_Intel
Employee
2,206 Views
after clicking 'X' button it throws deprecation warning and one warning related to not seeing window with the given name, but it is being set. 

This is caused by getWindowProperty call, basically the window is destroyed when user presses [X] and there is no way to check whether the window exists or not. So I suggest avoiding calling any window methods after waitKey because window can be closed. Alternatively you can try a trick: call waitKey(300) to initialize and show the window then getWindowProperty then waitKey with usual timeout in a loop. Probably explicit moveWindow or resizeWindow calls can actualize properties too.

 

Using cv2.WND_PROP_FULLSCREEN in cv2.namedWindow is wrong, see https://github.com/opencv/opencv/blob/d58b5ef74b91ba68ef89f9ce8be8725d0dfcaa0d/modules/highgui/include/opencv2/highgui/highgui_c.h#L110-L113 Though it works because constant is the same as cv2.WINDOW_NORMAL

 

Problem with setWindowTitle seem to be a bug in OpenCV and it looks like it has been fixed in the latest release. So it should be available in new OpenVINO too.

 

When modifying window parameters keep in mind that actual window update will be performed in waitKey which hides event loop under the hood. Traditional GUI frameworks usually have some callback or event handling mechanisms and OpenCV wraps it into very simple abstraction. I'd recommend using specialized GUI framework for advanced applications. And pure OpenCV questions are better to be asked on the OpenCV community forum: https://forum.opencv.org 

 

I tested with the following application in Ubuntu 21:

import cv2
name = "My test application"
logo_path = "logo.png"
logo = cv2.imread(logo_path)

cv2.namedWindow(name, 0) # basically only 0 and 1 are allowed
# Uncomment to enable fullscreen # cv2.setWindowProperty(name,cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.imshow(name, logo)
# Window creation and initialization
# cv2.waitKey(300)

# Prints warnings if user closes window by pressing [X]
# prop = cv2.getWindowProperty(name, cv2.WND_PROP_ASPECT_RATIO) # print(f"Aspect ratio: {prop}")
cv2.waitKey() 

 

0 Kudos
SergeyVasilyan
Beginner
2,150 Views

Hello Maksim,

Please find my notes in-lined in blue below:


@Maksim_S_Intel wrote:
after clicking 'X' button it throws deprecation warning and one warning related to not seeing window with the given name, but it is being set. 

This is caused by getWindowProperty call, basically the window is destroyed when user presses [X] and there is no way to check whether the window exists or not. So I suggest avoiding calling any window methods after waitKey because window can be closed. Alternatively you can try a trick: call waitKey(300) to initialize and show the window then getWindowProperty then waitKey with usual timeout in a loop. Probably explicit moveWindow or resizeWindow calls can actualize properties too.


Agree with you that the warnings are the result of the 'getWindowProperty' call. But in my case in previous versions that way checking worked without any issue. 

Currently my application flow is checking for window existing state during the camera stream. 

Using cv2.WND_PROP_FULLSCREEN in cv2.namedWindow is wrong, see https://github.com/opencv/opencv/blob/d58b5ef74b91ba68ef89f9ce8be8725d0dfcaa0d/modules/highgui/include/opencv2/highgui/highgui_c.h#L110-L113 Though it works because constant is the same as cv2.WINDOW_NORMAL


Thanks for your note, will add this fix in our code.

Problem with setWindowTitle seem to be a bug in OpenCV and it looks like it has been fixed in the latest release. So it should be available in new OpenVINO too.


Thanks for you information. Will wait for the new OpenVINO release as I currently using the latest available OpenVINO 2021.4.689 version.

When modifying window parameters keep in mind that actual window update will be performed in waitKey which hides event loop under the hood. Traditional GUI frameworks usually have some callback or event handling mechanisms and OpenCV wraps it into very simple abstraction. I'd recommend using specialized GUI framework for advanced applications. And pure OpenCV questions are better to be asked on the OpenCV community forum: https://forum.opencv.org 


Thanks for your suggestion. But want to mention that I am currently using pre-compiled OpenCV 4.5.3-openvino version that comes with OpenVINO.

I tested with the following application in Ubuntu 21:

import cv2
name = "My test application"
logo_path = "logo.png"
logo = cv2.imread(logo_path)

cv2.namedWindow(name, 0) # basically only 0 and 1 are allowed
# Uncomment to enable fullscreen # cv2.setWindowProperty(name,cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.imshow(name, logo)
# Window creation and initialization
# cv2.waitKey(300)

# Prints warnings if user closes window by pressing [X]
# prop = cv2.getWindowProperty(name, cv2.WND_PROP_ASPECT_RATIO) # print(f"Aspect ratio: {prop}")
cv2.waitKey() 

 

Tested your code on my side on Ubuntu 20.04. Both issues are still reproducible :

  • application name stays 'Python3' no matter what name is set to the window,
  • image is not being scaled in full screen.

But as soon as I am working with camera stream, where 'cv2.waitKey()' is not needed, above two issues are still reproducible and also a warnings when clicking 'X' button is appearing again.


Regards,
Sergey

0 Kudos
Peh_Intel
Moderator
1,989 Views

Thanks, Maksim, for providing the clarification about the bug regarding to setWindowTitle.

 


Hi Sergey,


Based on the updates from our development team, WINDOW_NORMAL supports window to "fullscreen", but it doesn't support image resize. Hence, the image is not being scaled to full screen as the window.


A proposed workaround is to resize the image before passing it to imshow() but need to know the size of the desktop area somehow prior to image resizing.



Regards,

Peh


0 Kudos
SergeyVasilyan
Beginner
1,936 Views

Hi Peh,

Thanks for your notes.

What can I see is that there is no any good way, i.e. without impacting the performance, to perform truly full-screen image showing logic in current OpenCV version like on previous ones so will proceed with workaround.


Regards,
Sergey

0 Kudos
Peh_Intel
Moderator
1,920 Views

Hi Sergey,


This thread will no longer be monitored since we have provided suggestions. If you need any additional information from Intel, please submit a new question. 



Regards,

Peh


0 Kudos
Reply