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.
Germany
Slovakia
Canada
Brazil
Singapore
Hungary
Philippines
Mexico
Thailand
Ukraine
Luxembourg
Estonia
Lithuania
Norway
Chile
United States
Great Britain
India
Spain
South Korea
Ecuador
Colombia
Taiwan
Switzerland
Indonesia
Cyprus
Denmark
Finland
Poland
Malta
Czechia
New Zealand
Austria
Turkey
France
Sweden
Italy
Egypt
Belgium
Portugal
Slovenia
Ireland
Romania
Greece
Argentina
Malaysia
South Africa
Netherlands
Bulgaria
Latvia
Australia
Japan
Russia