I have written this code to take a picture when it detects motion however when I run the code it prints 'picture taken' but does not save the picture. I know my camera works as I tested it in LX terminal with the raspistill command. I have also tried changing the path for the file to be saved. If you can see where i have been going wrong an answer would be greatly appreciated. Thanks
import RPi.GPIO as GPIO
import time
import picamera
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, GPIO.PUD_DOWN)
cam = picamera.PiCamera()
time.sleep(1)
if GPIO.input(4):
cam.capture('/home/pi/Eaglecam/surveillance.jpg')
print('picture taken')