Setup USB/External Webcam in Raspberry Pi with OpenCV 4.5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello viewers uh in this video we will see how we can set up an external webcam on raspberry pi uh you know that the latest version of the raspberry pi os uh the debian bullseye is out there so we'll see how we can set up the webcam and the opencv and then use opencv to capture images uh in this tutorial okay so here is my ssh terminal my raspberry pi is powered on and i have logged into my raspberry pi and also here is my vnc viewer i can control it by using both methods but the ssh is a little faster and the vnc is a little laggy so let's do some of the job in the ssh okay let's get started first let's check if our webcam is available to the raspberry pi or not we can do that by entering the following command it will list all the available usb devices so as you can see here the general webcam my webcam is listed here okay so to access the webcam first we need to use a library that is called the fs webcam to install that enter the command suit my apt install it is okay okay i have the library already installed so you can see it is showing me the message that the fs webcam is already used version but for your case it may take a minute or two to be installed okay now let's check if the fs webcam is working correctly or not will capture a image using the fs webcam uh library so first let's create a folder inside the slash forms let's buy directory so here new folder let's name it images okay so now let's enter this command to capture a image or the size will be 1280 into 720 and it will be under the images directory and the name will be image installed even this one the image1 will typically okay we need to enter the full path [Music] [Music] okay as you can see it has successfully written the image to the following location so let's check it okay we can see a image actually the webcam is mounted on top of my laptop and it is focused towards the keyboard keyboard of my laptop so you can see so if this video is working okay now we have to uh install the opencv library to use it with opencv so enter the following command [Music] [Music] okay so open city is already installed in my raspberry pi so you can see it is showing this message but for the first time before installing it it may take some time uh five to seven minutes so give it some time and it will be installed okay and you can see the version of the web of the opencv is 4.5.5 okay now let's check if it is correctly installed the version of my python is 3.9.2 okay let's try importing the opencv okay you can see it has been imported successfully so now we need to prepare the script or to capture image using the webcam so let it return the program let's see the full term [Music] okay first i'm importing the opencv library then importing the time library it's optional actually then uh using the video capture object from the opencv library and you can see the index is zero if you have multiple webcams then it may vary by default it is zero inside a while loop we are reading each frames from the video capture object and we will find the frames inside this variable img so we are displaying uh the frames we are grabbing and [Music] inside here we have two if statement the first one it actually uh waits and checks the key presses so if we press the key c on the keyboard it will capture uh image and i have written the program so that we can capture at least three images so it will increment the number of images and if we have successfully captured three images then it will break the loop and at last we have to release the video capture object and destroy all the windows okay so now let's go to the vnc viewer and run the program okay so let's press c you can see the message capture one successful so press c twice so capture two capture three and when capture three is successful uh it will automatically break the loop and exit the program okay so we'll find all the images inside this images folder here uh one two and three these two are from my other experiments and this one captured at first okay so that's all for today you
Info
Channel: Microcontrollers Explained
Views: 43,877
Rating: undefined out of 5
Keywords: opencv, raspberry pi usb camera, raspberry pi opencv, python, raspberry pi python, opencv python
Id: OEGR19aE0dg
Channel Id: undefined
Length: 7min 31sec (451 seconds)
Published: Thu Mar 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.