In this recipe, first, we import OpenCV. We then select the first camera it finds (camera(0)). If we were looking for the second camera it finds, then we would increment the camera number (camera(1)). Next, we check whether the camera is available. There can be several reasons why a camera might not be available. First, it could be opened by something else. You could, for example, open the camera in a different application to see whether it is working and this would prevent the Python application from detecting and connecting to the camera. Another common issue is that releasing the camera step in the code does not get executed and the camera needs to be reset. Next, we capture the video frames and present them on the screen until someone presses the Q key. Finally, after someone has exited the application, we release the camera and close the open window.
United States
United Kingdom
India
Germany
France
Canada
Russia
Spain
Brazil
Australia
Argentina
Austria
Belgium
Bulgaria
Chile
Colombia
Cyprus
Czechia
Denmark
Ecuador
Egypt
Estonia
Finland
Greece
Hungary
Indonesia
Ireland
Italy
Japan
Latvia
Lithuania
Luxembourg
Malaysia
Malta
Mexico
Netherlands
New Zealand
Norway
Philippines
Poland
Portugal
Romania
Singapore
Slovakia
Slovenia
South Africa
South Korea
Sweden
Switzerland
Taiwan
Thailand
Turkey
Ukraine