How to use smartphone camera with OpenCV (via USB) - Python - python

I am trying to use my iPhone camera with OpenCV. However, Python doesn't recognize the camera.
Some months ago I did it simply writing:
cap = cv2.VideoCapture(1)
Does anyone know how to solve this?
I know that there are other solutions like using IP address to use the camera with OpenCV, but I want to use the camera via USB.

As of now, your way of accessing the camera of your iPhone is not supported by OpenCV, but there are other ways to implement OpenCV on iOS.
OpenCV Documentation tells you to
add a camera controller to the view controller and initialize it when the view has loaded.
This is done using an XCode project utilizing the OpenCV Framework, more information can be found here: OpenCV iOS - Video Processing.

Related

Is there a way to convert/deploy a python project based on mediapipe and opencv on android?

I have made a pose estimation project using mediapipe and opencv in python. How can I convert or deploy it on android devices by using tools like Beeware/Chaquopy, or recode the whole thing in Kivy?
I am open to suggestions on changes in the project to incorporate it in android.

How can I access my laptop's built-in infrared webcam using python?

I'm trying to access my laptop's built-in infrared webcam (intended for windows hello) in a python project. I can access the normal RGB camera quite easily using the VideoCapture class from OpenCV, however can't find a way to access the infrared camera. I tried passing different indices to the VideoCapture class, however only "0" works, which is the normal webcam.
There are ways to do this using the Windows API, however I can't find a way to access this in Python.
Some people have been able to access the windows hello camera on Ubuntu using fswebcam.
Is there anyway to access the infrared camera using python? Maybe some way of interfacing with the Windows API using pywin32? Any help getting started with this would be appreciated. Alternatively, is there anything similar to fswebcam for Windows that would let me do the same?
That example you provided, doesn't seem to use the win32 api, but rather the dotnet framework, specifically the Windows.Media.Capture.Frames.MediaFrameSourceGroup class.
It looks like you'll be able to access the dotnet framework using http://pythonnet.github.io/ . After that it should be a case of porting that C# code over to Python.
You need to access WinRT API, not Win32 API.
Use this library: https://github.com/Microsoft/xlang/tree/master/src/package/pywinrt/projection and you should be able to call invoke necessary parts in WinRT from the code you posted.

HDMI-USB Video Capture Card Stream Using Opencv or any other library in Python

I am trying to read the stream from HDMI-USB video-capture card using opencv. But OpenCV doesn't seem to support that functionality. I used opencv to read RTSP streams and webcams. Can anyone suggest a way here. Currently I am accessing the stream using OBS Studio software. Is there any other module in python that I can use. Thanks in advance.
There's a similar question here. But that approach doesn't work for me.
Edit:
video0 or video1 depends on your system and connected devices.
Turns out we can access this USB device using opencv itself.
In linux you can access these devices at /dev/video0.
import cv2
cap = cv2.VideoCapture('/dev/video0')
I'm yet to figure out how to do this in windows though

How to use the stereo camera of Android phone for OpenCV in PC?

My question is a little different from this post.
My Android smartphone has a stereo rear camera setup which includes a normal 48MP camera and a 5MP depth sensor.
I am learning OpenCV with Python and for making some real-time applications, I need to use both of those cameras as a webcam for my PC since I want the depth information along with the image.
I have seen many posts and blogs which demonstrates the use of the phone's primary camera and there are many apps available for that purpose, but I haven't ever found anything regarding this setup of streaming stereo camera data from mobile to PC.
Is there currently any way to achieve what I want? If not, can you give me some guidance about how to create such a setup of my own? I don't mind if I need to create the programs myself.
If you need, here are my device information:
Mobile: Samsung Galaxy M21 with Android 10
PC running Ubuntu 20.04

How can I access my webcam using python or c

I want to create a GUI application which will access the local webcam and provide a feature of taking the snapshot from the stream . I want to develop this application using C/python . can anyone tell me how can I access my local webcam.
You can use OpenCV which has Python bindings to capture webcam streams.
You can try VideoCapture, it is "A Win32 Python Extension for Accessing Video Devices".
In Linux, you can use v4l2 by which you can get the full control of your webcam.

Categories