Reputation: 3379
I need a Mobile camera as webcam. I need to further process the camera video for my openCV application. But the softwares available for this purpose lacks required documentation of the api. (I mean how to access the phone camera interface) So can anyone give me good advice for this scenario. Thanks in advance.
Upvotes: 3
Views: 5586
Reputation: 349
To make it work, we first need a mobile client. You can download "IP webcam" app on your android phone. Configure the port(for example: 2333) and start server.
If you computer and mobile connect to the same local network, you can type the ip address shown on your phone app on your computer's web browser. That should be ok. In this way, the stream is transferred via wifi which is slow.
To improve the speed, you can connect via USB. We are going to redirect TCP stream over USB. Turn on debug mode on your android device and install android ADB tools on your computer. To forward the stream, the syntax is:
adb forward <local> <remote>
for example:
./adb forward tcp:5555 tcp:2333
forwarded your phone's 192.168.XX.XX:2333
to your computer's http://localhost:5555/
Then you can use this link.
To use in your OpenCV project, try the follow example:
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string videoStreamAddress = "http://localhost:5555/video";
//open the video stream and make sure it's opened
if(!vcap.open(videoStreamAddress)) {
std::cerr << "Error opening video stream or file" << std::endl;
return -1;
}
for(;;) {
vcap.read(image);
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
Upvotes: 2
Reputation: 25927
I think, that it's not actually a matter of openCV. I assume, that the application will run on the PC. You have two options:
Attempt to interface with phone's camera using device-specific drivers. Maybe some of them support such feature.
Write an application for your mobile, which will stream the video through WiFi, Bluetooth or in another way. Then write a set of drivers, which will attempt to retrieve the video feed and provide to the OS as a webcam.
Third option involves recording the video on the mobile and then transferring it to the PC, but I guess, that it's not an option.
Upvotes: 0