Pi TFT and OenCV : cannot open display

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
snoygues
 
Posts: 10
Joined: Tue Aug 26, 2014 6:28 am

Pi TFT and OenCV : cannot open display

Post by snoygues »

I try to use OpenCV lib (for Python) in order to display an image on Pi TFT screen.
here is my code :

import os
import cv2

#Load image
img = cv2.imread("/home/pi/image.jpg")

#Show Images
cv2.imshow("img",img)
cv2.waitKey(0)

If I run it from SSH, if open a new window and display my image inside it.
But if I run my script from Pi TFT shell : pi@raspberrypi ~ $ python toto.py
I get following error message : (im:2433): Gtk-WARNING **: cannot open display

Notes :
* it's not a problem of image loading
* actually, it works if I execute the script after loading "startx" and use "LxTerminal", but I would like use my soft directly from shell cmd.

somebody can help me ?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Pi TFT and OenCV : cannot open display

Post by adafruit_support_mike »

A shell command isn't associated with any output terminal, so the OS doesn't know where to send the image.

Try running the following script from either context to see how the environments are different:

Code: Select all

#!/usr/bin/python

import os
os.system("set > ~/env-log")

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”