9

I've got a prototype I need to show for an RFID project. I've got the RFID (Parallax USB) working, and the sample Python script (my first) is displaying the ID of the card just like it's supposed to... problem is, it's not a very compelling demo/prototype.

What I'd love to be able to do is launch my application on the pi and have a PNG display somehow. New window, full screen, etc. Then, when a card is detected by the Pi, it would swap the image being displayed (1.PNG for 2.PNG, etc).

What would be the most pragmatic, easiest, fastest way to have the screen display just an image file?

Here's my code that outputs the RFID:

#! /usr/bin/python
import serial
import time

ser = serial.Serial('/dev/ttyUSB0', 2400, timeout=1) # replace '/dev/ttyUSB0' with your port

while True:
    response = ser.read(12)
    if response <> "":
        print "raw: " + str(response)
        print "hex: " + str(response[-8:])
        print "dec: " + str(int(response[-8:], 16))
    time.sleep(1)

ser.close()
Jeff
  • 115
  • 1
  • 1
  • 4

3 Answers3

7

Wand has a display module/method.

In the terminal

$ python -m wand.display wandtests/assets/mona-lisa.jpg

In a Python script

import wand
with Image(blob=file_data) as image:
    wand.display.display(IMAGE)
Serge Stroobandt
  • 455
  • 7
  • 18
earthmeLon
  • 1,414
  • 1
  • 11
  • 23
6

If you're using an X11 Desktop Environment such as LXDE, then you can accomplish this using the basic logic shown in this article.

Here's what I came up with to switch displaying two images waiting 30 seconds between each switch. You should be able to insert your logic for switching the images based on what you read from your RFID sensor.

displayImages.py

#!/usr/bin/python

# use a Tkinter label as a panel/frame with a background image
# note that Tkinter only reads gif and ppm images
# use the Python Image Library (PIL) for other image formats
# free from [url]http://www.pythonware.com/products/pil/index.htm[/url]
# give Tkinter a namespace to avoid conflicts with PIL
# (they both have a class named Image)

import Tkinter as tk
from PIL import Image, ImageTk
from Tkinter.ttk import Frame, Button, Style
import time

class Example():
    def __init__(self):
        self.root = tk.Tk()
        self.root.title('My Pictures')

        # pick an image file you have .bmp  .jpg  .gif.  .png
        # load the file and covert it to a Tkinter image object
        imageFile = "babyAce.jpg"
        self.image1 = ImageTk.PhotoImage(Image.open(imageFile))
        self.image2 = ImageTk.PhotoImage(Image.open("baby-marti.jpg"))

        # get the image size
        w = self.image1.width()
        h = self.image1.height()

        # position coordinates of root 'upper left corner'
        x = 0
        y = 0

        # make the root window the size of the image
        self.root.geometry("%dx%d+%d+%d" % (w, h, x, y))

        # root has no image argument, so use a label as a panel
        self.panel1 = tk.Label(self.root, image=self.image1)
        self.display = self.image1
        self.panel1.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES)
        print "Display image1"
        self.root.after(30000, self.update_image)
        self.root.mainloop()

def update_image(self):
    if self.display == self.image1:
        self.panel1.configure(image=self.image2)
        print "Display image2"
        self.display = self.image2
    else:
        self.panel1.configure(image=self.image1)
        print "Display image1"
        self.display = self.image1
    self.root.after(30000, self.update_image)       # Set to call again in 30 seconds

def main():
    app = Example()

if __name__ == '__main__':
    main()

You should be able to modify this to wait 1000 ms and test your RFID status to determine which image to display.

HeatfanJohn
  • 3,115
  • 3
  • 26
  • 38
2

If you want to display an image from the command line, you can use the "fbi" console program with sudo apt-get install -y fbi

Ivoah
  • 49
  • 3