Sunday 1 December 2013

Access smartphone's webcam in opencv in c++

This post  describe you how to access ipwebcam from your smartphone to your project in opencv. I faced very difficulty to find solution of this problem on internet. Now I have solved this problem and decide to share it for helping others who is seeking with this problem.
First you need to download ip-webcam in your smartphone. I am using android v3.6 . You can download ipwebcam from google play store. Now when you start server it generate ip address based on your network. If you are using internet then it provide your isp address. If you connected to wifi then it will generate your device ip-address and If you are using tethering hotspot then it will generate gateway ip-address. Whatever when you get the ip-address you need to open it in your computer in any browser. I am supposing your ip-address is http://192.168.100.1:8080
Now come to second part ...
In Visual Studio 2010 and opencv I am using c++ programming. The only way to access webcam from mobile is write a code to download image from ip-address to your computer and you can use that image for further processing. Here is code.

//Code:

#include <math.h>
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include<UrlMon.h>
#include<tchar.h>
#pragma comment(lib,"urlmon.lib")


using namespace cv;
using namespace std;


int main()
{
    Mat capf;
    for(;;)
    {
HRESULT hr = URLDownloadToFile(NULL,
        _T("http://192.168.43.1:8080/shot.jpg"),
        _T("e:/ptest.jpg"),0,NULL);

    //IplImage *test=cvLoadImage("e:/ptest.jpg");
    capf=imread("e:\\ptest.jpg");
    imshow("test",capf);
    cvWaitKey(30);
    }
    system("pause");
    return 0;
}


This program grab an image from your mobile webcam and store it in particular location (any drive) and next line in code open that image in your opencv window for further processing. This process is slow but very usefull in various application.
I am not a professional so my explaination is rough type. All you need to grab information from this post. Further any query leave a comment. Thank You.

1 comment:

  1. Laws Of Technology: Access Smartphone'S Webcam In Opencv In C++ >>>>> Download Now

    >>>>> Download Full

    Laws Of Technology: Access Smartphone'S Webcam In Opencv In C++ >>>>> Download LINK

    >>>>> Download Now

    Laws Of Technology: Access Smartphone'S Webcam In Opencv In C++ >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete