Firstly, I've googled around, but got myself horribly confused; hence this question.
I have a headless/keyboardless Raspberry pi with a camera board on it, that I connect to via ssh using my windows PC.
I'm trying to display a window, on my windows PC, with a picture taken using a python script and opencv2, but am having problems doing that.
I am using putty and xming, and can see the raspberry pi's desktop. I run the script via the terminal on the PI's desktop.
The below script saves, and rotates the jpg, but doesn't display the picture on my pc and gives an error:
PuTTY X11 proxy: MIT-MAGIC-COOKIE-1 data did not match
(image:18543): Gtk-WARNING **: cannot open display: localhost:10.0
Script:
#!/usr/bin/env python
import cv2
# Camera 0 is the integrated web cam on my netbook
camera_port = 0
#Number of frames to throw away while the camera adjusts to light levels
ramp_frames = 60
# Now we can initialize the camera capture object with the cv2.VideoCapture class.
# All it needs is the index to a camera port.
camera = cv2.VideoCapture(camera_port)
camera.set(3,900)
camera.set(4,700)
# Captures a single image from the camera and returns it in PIL format
def get_image():
# read is the easiest way to get a full image out of a VideoCapture object.
retval, im = camera.read()
(h, w) = im.shape[:2]
center = (w / 2, h / 2)
# rotate the image by 180 degrees
M = cv2.getRotationMatrix2D(center, 180, 1.0)
rotated = cv2.warpAffine(im, M, (w, h))
return rotated
# Ramp the camera - these frames will be discarded and are only used to allow v4l2
# to adjust light levels, if necessary
for i in xrange(ramp_frames):
temp = get_image()
print("Taking image...")
# Take the actual image we want to keep
camera_capture = get_image()
file = "/usr/src/scripts/test_image_1_from_open_cv2.jpg"
# A nice feature of the imwrite method is that it will automatically choose the
# correct format based on the file extension you provide. Convenient!
cv2.imwrite(file, camera_capture)
cv2.imshow('image', camera_capture)
# You'll want to release the camera, otherwise you won't be able to create a new
# capture object until your script exits
del(camera)
I also get a load of messages when I start the xming server from putty using startlxde
Obt-Message: Xinerama extension is not present on the server
** (lxpolkit:11032): CRITICAL **: polkit_agent_listener_register_with_options: a ssertion 'POLKIT_IS_SUBJECT (subject)' failed
(lxpolkit:11032): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJE CT (object)' failed
(lxpanel:11026): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-can-change-accels after class was initialised
(lxpanel:11026): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-menu-popup-delay after class was initialised
(lxpanel:11026): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-menu-popdown-delay after class was initialised
(lxpanel:11026): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-menu-images after class was initialised
(lxpanel:11026): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-label-select-on-focus after class was initialised
(pcmanfm:11027): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-can-change-accels after class was initialised
(pcmanfm:11027): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-menu-popup-delay after class was initialised
(pcmanfm:11027): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-menu-popdown-delay after class was initialised
(pcmanfm:11027): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-label-select-on-focus after class was initialised
(pcmanfm:11027): GLib-GObject-WARNING **: Attempt to add property GtkSettings::g tk-menu-images after class was initialised
Openbox-Message: A window manager is already running on screen 0
(lxterminal:11188): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-bar-popup-delay after class was initialised
(lxterminal:11188): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-can-change-accels after class was initialised
(lxterminal:11188): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-popup-delay after class was initialised
(lxterminal:11188): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-popdown-delay after class was initialised
(lxterminal:11188): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-label-select-on-focus after class was initialised
(lxterminal:11188): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-images after class was initialised
(lxterminal:11188): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-button-images after class was initialised
(lxterminal:11313): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-bar-popup-delay after class was initialised
(lxterminal:11313): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-can-change-accels after class was initialised
(lxterminal:11313): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-popup-delay after class was initialised
(lxterminal:11313): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-popdown-delay after class was initialised
(lxterminal:11313): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-label-select-on-focus after class was initialised
(lxterminal:11313): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-images after class was initialised
(lxterminal:11313): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-button-images after class was initialised
(lxterminal:11388): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-bar-popup-delay after class was initialised
(lxterminal:11388): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-can-change-accels after class was initialised
(lxterminal:11388): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-popup-delay after class was initialised
(lxterminal:11388): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-popdown-delay after class was initialised
(lxterminal:11388): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-label-select-on-focus after class was initialised
(lxterminal:11388): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-menu-images after class was initialised
(lxterminal:11388): GLib-GObject-WARNING **: Attempt to add property GtkSettings ::gtk-button-images after class was initialised
Iv'e done some more tests and this is what ive found out, so far:
a) I logged in to my pi via xming and putty as user pi.
I then created a shortcut to the script, and ran it, which worked and created an image on the desktop of my pi.
Python script shortcut:
[Desktop Entry]
Name=Python script shortcut
Comment=Integrated DeveLopment Environment for Python3
Exec=/usr/src/scripts/videocap_opencv2_1.py
Terminal=false
Type=Application
Categories=Application;Development;
StartupNotify=true
It then temporarily displayed a new "image" window.
b) But when I changed the Exec=/usr/src/scripts/videocap_opencv2_1.py
to Exec=sudo /usr/src/scripts/videocap_opencv2_1.py
the script saves a jpg but didn't display a new "image" window.
c) With this in mind, I then tried /usr/src/scripts/videocap_opencv2_1.py
in LXTerminal on the desktop, which didn't display the "image" window, but did produce the jpg and when I didsudo /usr/src/scripts/videocap_opencv2_1.py
it takes the image but i get the error again:
PuTTY X11 proxy: MIT-MAGIC-COOKIE-1 data did not match
(image:4049): Gtk-WARNING **: cannot open display: localhost:10.0
1) why don't I get the "image" , regardless of using sudo window when I launch the script via XLTerminal?
2) is there a non GUI way of launching this script, rather than creating a desktop shortcut?