0

While running the following shell command (via pyhtonanywhere bash):

cv2.imshow('Mask',mask)

I get the error message:

qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/teki/.virtualenvs/bup/lib/python3.9/site-packages/cv2/qt/plugins" ev
en though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

As suggested in this forum (see example) I unistall opencv-python and installed then opencv-python-headless, message raised the gollowing error message:

pythonanywhete cv2.error: OpenCV(4.6.0) /io/opencv/modules/highgui/src/window.cpp:1267: error: (-2:Unspecified error) The function is not implemented. R ebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re -run cmake or configure script in function 'cvShowImage'

Comments on this forum suggest to uninstall opencv-python-headless and to install opencv-python...which brings me back to my initial problem.

Any tip on this problem would be highly appreciated.

PS- in case it helps, here's the full script:

# import required libraries
import cv2
import numpy as np

# read input image
img = cv2.imread('car.jpg')

# Convert BGR to HSV
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# define range of blue color in HSV
lower_yellow = np.array([15,50,180])
upper_yellow = np.array([40,255,255])

# Create a mask. Threshold the HSV image to get only yellow colors
mask = cv2.inRange(hsv, lower_yellow, upper_yellow)

# Bitwise-AND mask and original image
result = cv2.bitwise_and(img,img, mask= mask)

# display the mask and masked image
cv2.imshow('Mask',mask) #my script runs well till this line. 
cv2.waitKey(0)
cv2.imshow('Masked Image',result)
cv2.waitKey(0)
cv2.destroyAllWindows()
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
donbonbon
  • 81
  • 1
  • 8
  • 1
    If you install **OpenCV** *"headless"*, that means it doesn't have access to a screen to display graphical images so you can't use `cv2.imshow()` to display images and you'll have to use your system's image viewer or something else (e.g. **matplotlib**, `imgcat` or somesuch) to display it. If you install it normally, i.e. not headless, you need to have a screen/display available for `cv2.imshow()` to access - that likely means you need a properly configured X11 server that all X11 programs (such as `xclock`) can display on, or you need something that runs Qt or similar. – Mark Setchell Dec 08 '22 at 10:29
  • try installing pip3 install opencv-python==4.1.2.30 – Majid Dec 08 '22 at 12:01
  • 1
    Thanks @Mark Setchell, not only you answered my needs, but also helped me to learn something new... I should close the topic, not sure though how to credit your comment as the answer. – donbonbon Dec 08 '22 at 13:28
  • Does this answer your question? [Could not find or load the Qt platform plugin "xcb"](https://stackoverflow.com/questions/33051790/could-not-find-or-load-the-qt-platform-plugin-xcb) – Christoph Rackwitz Dec 08 '22 at 18:57
  • 2
    pythonanywhere is a web site. code running on web servers can't show any GUI. – Christoph Rackwitz Dec 08 '22 at 18:57
  • 1
    I'm kind of repeating what @ChristophRackwitz said, but to put it in different words: when you run code on PythonAnywhere, it's running on a server in a datacenter, not on your own computer. That server does not have a display, so you can't run GUI code on it (and if it did have a display, you wouldn't have access to it). – Giles Thomas Dec 10 '22 at 15:33

0 Answers0