1

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.

enter image description here

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?

3

Look at this link: https://tekyblog.wordpress.com/2012/02/02/how-to-setup-x11-forwarding-in-putty-using-xming/

Resolution (as per that website)

RPi> su – root
RPi> xauth list

10-111-11-11/unix:10 MIT-MAGIC-COOKIE-1 cf4967d5a6c0e6d5f33285aa0e483643

RPi> su – <user> (probably "pi")
RPi> xauth add 10-111-11-11/unix:10 MIT-MAGIC-COOKIE-1 cf4967d5a6c0e6d5f33285aa0e483643
  • X11 forwarding is definitely the problem, so this answer should fix it. – Mast Mar 5 '15 at 16:07
  • I followed the steps in the above link, but still I get exactly same error message and no window appearing with jpg in. step 10 (xclock) gave bash: xclock: command not found. xauth list gives raspberrypi/unix:10 MIT-MAGIC-COOKIE-1 xxxxlongstringxxx – reggie Mar 6 '15 at 5:00
1

I had a similar problem. I know this Question is 3 years old. But my search landed me here. So just answering the question

sudo cp ~pi/.Xauthority ~root/

This just copies the X11 authority file directly to root without the xauth command management. This will make all active user pi X11 connections available for use by root without having to sort through and find the correct one.

P.S : I'm just copy pasting, credit goes to Bill answer in the link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.