cv2.imshow() cannot connect to X server

Viewed 635

i have python code like this

import cv2
import numpy
img = np.zeros([512,512,1], dtype=np.uint8)
img.fill(255)
cv2.imshow('test', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

it should be show blank image with white background. i can run this on terminal, but when im running this on visual studio code, its shows

: cannot connect to X server

previously i can do this on my visual studio code and now i cannot do this again. my settings in linux are :

  • Ubuntu 20.04
  • Python 3.8
  • Opencv 4

i know there are many question about this issue, i already try

  • xhost local:root
  • import os os.environ['DISPLAY'] = ':0'

but nothing can solved my issue. i also re-install opencv and visual studio code. any help would appreciate. thank you very much

0 Answers
Related