Gtk-警告**:无法打开显示:树莓派 opencv

Hid*_*oka 3 opencv python-3.x raspberry-pi

  • 树莓派 B 型
  • OpenCV 3.0.0
  • 蟒蛇 3.6.x

无法通过 openCV 显示图像。ex) imshow() 这里是我的源代码。

def show_captured_image(path):
    img = cv2.imread(path, 1)
    resize_img = cv2.resize(img, (480, 320))
    xy_axis = cv2.flip(resize_img, -1)
    cv2.imshow("img", xy_axis)
    cv2.moveWindow("img", 0, 0)
    cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)

(img:2984): Gtk-WARNING **: cannot open display: 发生在这一行。

请告诉我解决方法!

小智 9

尝试export DISPLAY=":0"在运行脚本之前从 ssh 会话执行。它应该将您的显示器设置为连接到树莓派的显示器。