top of page

OpenCV Basics

Now that the setup is complete, we can move on to basic OpenCV functions such as opening the camera stream and viewing its contents live on your computer screen. The following code will allow you to open up the video stream and achieve the aforementioned objectives.


# Simple camera startup script import cv2 cap = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = cap.read() frame = cv2.flip(frame, 1) # Display the resulting frame cv2.imshow('frame',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything is done, release the capture cap.release() cv2.destroyAllWindows()


This would allow you to view your webcam's live stream on your laptop screen. By connecting more peripheral cameras via your laptop's USB port (or Raspberry Pi's USB ports), you can select which video stream you want to open up very easily, but simply changing the value in cv2.VideoCapture(), 0 by default should be the always-available camera, the laptop's webcam, in the case of a laptop.


If the camera stream can not be opened, an error will be thrown at runtime. Therefore it is very important to ensure that any peripheral cameras are powered up properly to ensure that any stream opening errors are avoided.


About Me.

I'm a paragraph. Click here to add your own text and edit me. I’m a great place for you to tell a story and let your users know a little more about you.

  • Black Facebook Icon
  • Black Instagram Icon
  • Black Twitter Icon
Never Miss a Post!
bottom of page