For those of you playing along at home as we learn Artificial Intelligence on the Jetson Nano, the code below is what we do to launch a camera using OpenCV. We include code that will launch either the Raspberry Pi Camera, or a WEB cam like the Logitech 920. Check out our Youtube Jetson Nano Channel to follow along the full tutorial. The Jetson Nano tutorial Play List can be found HERE:
The code below is the starting point for most of the lessons:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import cv2 print(cv2.__version__) dispW=640 dispH=480 flip=2 #Uncomment These next Two Line for Pi Camera #camSet='nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink' #cam= cv2.VideoCapture(camSet) #Or, if you have a WEB cam, uncomment the next line #(If it does not work, try setting to '1' instead of '0') #cam=cv2.VideoCapture(0) while True: ret, frame = cam.read() cv2.imshow('nanoCam',frame) if cv2.waitKey(1)==ord('q'): break cam.release() cv2.destroyAllWindows() |