Hideki Tsuruoka
Hideki Tsuruoka

Reputation: 89

Gtk-WARNING **: cannot open display: raspberry pi opencv

Cannot show image via openCV. ex) imshow() here is my source code.

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)

(img:2984): Gtk-WARNING **: cannot open display: occurs in this line.

please tell me the solution!

Upvotes: 5

Views: 17614

Answers (3)

Rahul Sood
Rahul Sood

Reputation: 109

in this case, you may have a headless raspberry pi, which has no display. please check it, if true, it means rasppi is not able to show anything. you must it must show the display on your computer from which you are ssh'ing. for that you must disable the access control on your computer.

  1. Open new terminal and type command xhost+ now you have disabled the access control on your computer,
  2. now do ssh login on raspberry pi using command **ssh -X instead of just ssh ,now open the python-opencv application,it will work**

Upvotes: 1

HelpingHand
HelpingHand

Reputation: 9

Are you ssh'ing to the raspberry pi from another computer? If so you will have to set your display to the ip of that computer your ssh'ing from.

DISPLAY (IP Address):0; export DISPLAY

Upvotes: 0

Armata007
Armata007

Reputation: 153

Try executing export DISPLAY=":0" from your ssh session just before running the script. It should set your display to the one connected to the raspberry pi.

Upvotes: 11

Related Questions