NameError: name 'camera' is not defined in Interactive Classification Tool

My attempts to “create your camera and set it to running” in the DLI lesson of “Interactive Classification Tool” regularly returns the error of “NameError: name ‘camera’ is not defined”. The Raspberry Pi Camera Module V2 purchased from “sparkfun” worked as intended in the prior Hello Camera lesson. Firefox did not work so am using Chrome. I am a complete novice at Python and suspect that part of the dilemma may be that I may have not yet found a correct way to “Uncomment the appropriate camera selection lines…”. I “Shutdown Kernel” between each attempt and have restarted JupyterLab multiple times.

Assistance would be greatly appreciated.

The related “full reset of the camera” and “Traceback” and information is copied below.


Full reset of the camera

!echo ‘dlinano’ | sudo -S systemctl restart nvargus-daemon && printf ‘\n’

Check device number

!ls -ltrh /dev/video*

USB Camera (Logitech C270 webcam)

from jetcam.usb_camera import USBCamera

camera = USBCamera(width=224, height=224, capture_device=0) # confirm the capture_device number

CSI Camera (Raspberry Pi Camera Module V2)

from jetcam.csi_camera import CSICamera

camera = CSICamera(width=224, height=224)

camera.running = True
print(“camera created”)

[sudo] password for dlinano:
crw-rw----+ 1 root video 81, 0 Jun 14 21:48 /dev/video0

NameError Traceback (most recent call last)
in
12 # camera = CSICamera(width=224, height=224)
13
—> 14 camera.running = True
15 print(“camera created”)

NameError: name ‘camera’ is not defined

Problem Solved

After much experimentation I found that removing the “#” and space from the two CSI lines, as noted in the example below apparently, constitutes “uncomment” because this resolved the “NameError: name ‘camera’ not defined” , which gratefully allows continuation of the lesson. And now I understand a little bit more about Python coding that is well known by those “skilled at the art”.

CSI Camera (Raspberry Pi Camera Module V2)

from jetcam.csi_camera import CSICamera
camera = CSICamera(width=224, height=224)

1 Like

I had the same problem with the USBcam, but your post saved me, thanks