Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.imshow() is opening multiple window in a loop

Tags:

python

opencv

when I am running this simple code in my notebook with opencv-python version v4.3.0. Then my screen is filled with windows as shown in image.enter image description here

# importing the required modules 
  

import cv2 
  

import numpy as np 
  
  

# capturing from the first camera attached 
  

cap = cv2.VideoCapture(0) 
  
  

# will continue to capture until 'q' key is pressed 
 

 

while True: 
     ret, frame = cap.read() 
  
     # Capturing in grayscale 
     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
  
     cv2.imshow('frame', frame) 
     cv2.imshow('gray', gray) 
  
     # Program will terminate when 'q' key is pressed 
     if cv2.waitKey(1) & 0xFF == ord('q'): 
         break
  
 

# Releasing all the resources 
cap.release() 
cv2.destroyAllWindows() 
like image 417
Praveen yadav Avatar asked Dec 20 '25 04:12

Praveen yadav


1 Answers

I had the same problem with OpenCV 4.3.0. How I solved it:

1/ Uninstall the previous version:

$ pip uninstall opencv-contrib-python

2/ Install a previous version:

$ pip install opencv-contrib-python==4.2.0.34

It should work now.

like image 58
jclisbon Avatar answered Dec 21 '25 19:12

jclisbon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!