2

I want to be able to take a photo with the Raspberry Pi camera, put an image where the green screen is, and post it to twitter. I don't know how to implement it with my current code. Currently, the program takes a photo, overlays a .PNG file on top of it, and posts it to twitter. One button takes a photo and one button tweets the photo.

I'm not really sure how to proceed as I am a novice. I wasn't able to find many tutorials online.

from picamera import PiCamera
from gpiozero import Button
from overlay_functions import *
from time import gmtime, strftime
from guizero import App, PushButton, Text, Picture
from twython import Twython
from auth import (
    consumer_key,
    consumer_secret,
    access_token,
    access_token_secret
)

# Tell the next overlay button what to do
def next_overlay():
    global overlay
    overlay = next(all_overlays)
    preview_overlay(camera, overlay)

# Tell the take picture button what to do
def take_picture():
    global output
    output = strftime("/home/pi/allseeingpi/image-%d-%m %H:%M.png", gmtime())
    camera.capture(output)
    camera.stop_preview()
    remove_overlays(camera)
    output_overlay(output, overlay)

    # Save a smaller gif
    size = 400, 400
    gif_img = Image.open(output)
    gif_img.thumbnail(size, Image.ANTIALIAS)
    gif_img.save(latest_photo, 'gif')

    # Set the gui picture to this picture
    your_pic.set(latest_photo)


def new_picture():
    camera.start_preview(alpha=128)
    preview_overlay(camera, overlay)


def send_tweet():
    twitter = Twython(
        consumer_key,
        consumer_secret,
        access_token,
        access_token_secret
    )

    # Send the tweet
    message = "The All Seeing Pi saw you!"
    with open(output, 'rb') as photo:
        twitter.update_status_with_media(status=message, media=photo)

# Set up buttons
next_overlay_btn = Button(23)
next_overlay_btn.when_pressed = next_overlay
take_pic_btn = Button(25)
take_pic_btn.when_pressed = take_picture

# Set up camera (with resolution of the touchscreen)
camera = PiCamera()
camera.resolution = (1024, 768)
camera.hflip = True

# Start camera preview
camera.start_preview(alpha=128)

# Set up filename
output = ""

latest_photo = '/home/pi/allseeingpi/latest.gif'

app = App("The All Seeing Pi", 800, 480)
#app.attributes("-fullscreen", True)
message = Text(app, "I spotted you!")
your_pic = Picture(app, latest_photo)
new_pic = PushButton(app, new_picture, text="New picture")
tweet_pic = PushButton(app, send_tweet, text="Tweet picture")
app.display()

Currently it tweets an image of a photo and an overlay but I want it to be able to select what background you want in the image as well.

  • 1
    Where's the image with the green screen please? – Mark Setchell Aug 13 '19 at 21:50
  • The program currently tweets the image and saves it on the pi. – disasterouspizza Aug 13 '19 at 21:56
  • I don't understand. You have an initial image and you take a photo and want to place the photo in the original image where it is green. So where is the initial image with the green in it please? – Mark Setchell Aug 13 '19 at 21:58
  • 1
    Please try and be clearer about what the problem is. Is taking the photo the problem? Is tweeting the photo the problem? Is pasting one photo onto another photo the problem? – Mark Setchell Aug 13 '19 at 22:02
  • I currently have two buttons. It opens a camera and you can see yourself. You can change an overlay over the photo with one button and take a photo with another. Once you take a photo, you can tweet it or take another photo. My problem is I don't know how to replace one color of the background and ,using the third button, change the background. – disasterouspizza Aug 13 '19 at 22:06

0 Answers0