himani18
Posts: 44
Joined: Fri Feb 19, 2016 4:52 pm

How can I view captured images in rpi

Wed Mar 30, 2016 9:55 am

I have implemented the following code..
Everything worked perfectly fine for me..
but I don't know how to view the captured images in rpi...
So Can Anyone tell me how to view the captured images :P

Code: Select all

import RPi.GPIO as GPIO
import time
import picamera  # new

sensor = 4

GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)

previous_state = False
current_state = False

cam = picamera.PiCamera()  # new

while True:
    time.sleep(0.1)
    previous_state = current_state
    current_state = GPIO.input(sensor)
    if current_state != previous_state:
        new_state = "HIGH" if current_state else "LOW"
        print("GPIO pin %s is %s" % (sensor, new_state))
        if current_state:  # new
            cam.start_preview()
        else:
            cam.stop_preview()

gordon77
Posts: 5036
Joined: Sun Aug 05, 2012 3:12 pm

Re: How can I view captured images in rpi

Wed Mar 30, 2016 10:00 am

What have you saved ?

I think you need to add something like cam.start_recording('video.h264')

and then cam.stop_recording

himani18
Posts: 44
Joined: Fri Feb 19, 2016 4:52 pm

Re: How can I view captured images in rpi

Wed Mar 30, 2016 10:17 am

I have added these new line.
Now how can i view the captured images

Code: Select all

import RPi.GPIO as GPIO
import time
import picamera
import datetime  # new

def get_file_name():  # new
    return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")

sensor = 4

GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)

previous_state = False
current_state = False

cam = picamera.PiCamera()

while True:
    time.sleep(0.1)
    previous_state = current_state
    current_state = GPIO.input(sensor)
    if current_state != previous_state:
        new_state = "HIGH" if current_state else "LOW"
        print("GPIO pin %s is %s" % (sensor, new_state))
        if current_state:
            fileName = get_file_name()  # new
            cam.start_preview()
            cam.start_recording(fileName)  # new
        else:
            cam.stop_preview()
            cam.stop_recording() 

gordon77
Posts: 5036
Joined: Sun Aug 05, 2012 3:12 pm

Re: How can I view captured images in rpi

Wed Mar 30, 2016 10:19 am

try omxplayer

himani18
Posts: 44
Joined: Fri Feb 19, 2016 4:52 pm

Re: How can I view captured images in rpi

Wed Mar 30, 2016 10:20 am

how to use omxplayer??

gordon77
Posts: 5036
Joined: Sun Aug 05, 2012 3:12 pm

Re: How can I view captured images in rpi

Wed Mar 30, 2016 10:23 am

type........ omxplayer filename.h264

himani18
Posts: 44
Joined: Fri Feb 19, 2016 4:52 pm

Re: How can I view captured images in rpi

Wed Mar 30, 2016 2:12 pm

pi@raspberrypi:~/pi_pictures/video $ omxplayer video.h264
Video codec omx-h264 width 1920 height 1080 profile 100 fps 25.000000
Subtitle count: 0, state: off, index: 1, delay: 0
V:PortSettingsChanged: 1920x1080@25.00 interlace:0 deinterlace:0 anaglyph:0 par:1.00 display:0 layer:0 alpha:255 aspectMode:0
have a nice day ;)

I got this thing... :P

gordon77
Posts: 5036
Joined: Sun Aug 05, 2012 3:12 pm

Re: How can I view captured images in rpi

Wed Mar 30, 2016 3:46 pm

Is it showing the video ?

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: How can I view captured images in rpi

Wed Mar 30, 2016 3:50 pm

himani18 wrote:pi@raspberrypi:~/pi_pictures/video $ omxplayer video.h264
Looking at your script "video.h264" is not the file name you saved it as. You used "%Y-%m-%d_%H.%M.%S.h264" as the filename. You'll need to look at the file you saved and use the actual file name to play it.

Code: Select all

ls -l ~/pi_pictures/video
ETA: You got the "Have a nice day" termination message because it couldn't find a file named "video.h264"

Return to “Beginners”