In this script :-
camera_port = 0
ramp_frames = 400
camera = cv2.VideoCapture(camera_port)
def get_image():
global camera
retval, im = camera.read()
return im
def Camera():
global camera
for i in xrange(ramp_frames):
temp = get_image()
print("Taking image...")
camera_capture = get_image()
file = "opencv.png"
cv2.imwrite(file, camera_capture)
del(camera)
def Sendmail():
loop_value = 1
while loop_value==1:
try:
urllib2.urlopen("https://google.com")
except urllib2.URLError, e:
print "Network currently down."
sleep(20)
else:
print "Up and running."
loop_value = 0
def Email():
loop_value = 2
while loop_value==2:
try:
Camera()
Sendmail()
yag = yagmail.SMTP('email', 'pass')
yag.send('[email protected]', subject = "This is opencv.png", contents = 'opencv.png')
print "done"
except smtplib.SMTPAuthenticationError:
print 'Retrying in 30 seconds'
sleep(30)
else:
print 'Sent!'
sleep(20)
loop_value = 2
I get this error :-
What am I doing wrong. I have even defined camera globally, that to TWICE. Can somone please point out my mistake in the code? I use python 2.7 with Opencv module
File "C:\Python27\Scripts\Servers.py", line 22, in Camera
temp = get_image()
File "C:\Python27\Scripts\Servers.py", line 16, in get_image
retval, im = camera.read()
NameError: global name 'camera' is not defined
UPDATE Look above for updated code
global camerato the function in order to use it.Camera()you will delete the reference tocamera(last line). From this point onward it should not be defined.