Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How do I use my smart phone camera as a webcam in MATLAB?

Asked by Ashish Uthama

Ashish Uthama (view profile)

on 20 Jul 2011
Latest activity Edited by Amrinder Brar

Amrinder Brar (view profile)

on 25 Mar 2015 at 17:36

I have an smartphone device with a camera. I would like to obtain and process this image data in MATLAB.

(Specifically, I have an Android device).

1 Comment

Sarah Mahmood

Sarah Mahmood (view profile)

on 3 Jun 2013

is there any other solution that make matlab still running in the foreground, I tried this method yet it require the ip cam to run in the foreground i need matlab to be still running for later image processing. Also is it possible to access the smart phone camera using matlab mobile Specifically to iphone camera ?

Ashish Uthama

Ashish Uthama (view profile)

Products

No products are associated with this question.

4 Answers

Answer by Ashish Uthama

Ashish Uthama (view profile)

on 20 Jul 2011
Accepted answer

The general solution would need two parts, one to broadcast the data from the device and another part to read this data into MATLAB.

A specific solution for Android:

  • Install the free IP Webcam app. (Make sure you read the corresponding permissions and understand any security issues therein)
  • Open the app, set the desired resolution (will impact the speed!)
  • Scroll to the bottom and tap on 'Start Server'
  • In the camera preview window, note the url at the bottom of the screen.
  • Open MATLAB and use this code snippet to obtain a live preview window. Note that this uses JPG files for discrete frames, which is probably not the fastest way. The app can stream the video and/or audio in multiple ways.
url = 'http://<ip address>/shot.jpg';
ss  = imread(url);
fh = image(ss);
while(1)
    ss  = imread(url);
    set(fh,'CData',ss);
    drawnow;
end

Example:

(If you find faster ways/solutions for other devices, post it here!)

8 Comments

Walter Roberson

Walter Roberson (view profile)

on 9 Mar 2013
set(fh, 'CData', rgb2gra(ss));

And be sure that you have done

 colormap(gray(256))

after the original image() call.

Joshua

Joshua (view profile)

on 22 Jul 2013

I'm using a GoPro HD camera which has a URL via an Ambarella video player as http://10.5.5.9:8080/live/amba.m3u8. This is the network address to play in a VLC player. I want to use Matlab for further processing options.

What's the purpose of the .jpg string of the url input? I use the same code as above for the iPhone and Android with the '.jpg' extension on my URL and get the error message...

Error using imread (line 331) Can't read URL "http://10.5.5.9:8080/live/amba.m3u8.jpg".

Current input in command window is url = 'http://10.5.5.9:8080/live/amba.m3u8.jpg'; ss = imread(url); fh = image(ss);

while(1) ss = imread(url); set(fh,'CData',ss); drawnow; end

Very nice Thank You!!

Ashish Uthama

Ashish Uthama (view profile)

Answer by Chirag Gupta

Chirag Gupta (view profile)

on 20 Jul 2011

With the iPhone, using the App suggested by Ashish above (IP Cam), you can achieve the same pretty easily! The code is exactly the same:

url = 'http://<ipaddress>:8020/image.jpg';
ss  = imread(url);
fh = image(ss);
while(1)
    ss  = imread(url);
    set(fh,'CData',ss);
    drawnow;
end  

4 Comments

Francisco Canto

Francisco Canto (view profile)

on 4 Mar 2012

Hi, Excuse me for my bad English. I'm using IP webcam for Android.I used
url = 'http://158.124.30.101:8080/shot.jpg';
ss = imread(url);
fh = image(ss);
The video is excellent but my problem is that I want to use a bounding box to sellect a red object in the video. I don't know if it's possible. Can anyone help me?thanks

Ashish Uthama

Ashish Uthama (view profile)

on 21 Mar 2012

Francisco, you'll get a better answer if you ask this as a new question: http://www.mathworks.com/matlabcentral/answers/questions/new

(also look at http://www.mathworks.com/matlabcentral/fileexchange/28512-simple-color-detection-by-hue for example)

Joshua

Joshua (view profile)

on 22 Jul 2013

is the IP address for the android webcam streaming live video or simply a single image or series of saved images?

Chirag Gupta

Chirag Gupta (view profile)

Answer by amro

amro (view profile)

on 10 May 2014
    url=('http://192.168.43.1:8080/shot.jpg?rnd=350264');
    hVideoIn = vision.VideoPlayer('Name', 'Final Video');
    while(1)
        ss=imread(url);
        step(hVideoIn,ss)
    end

0 Comments

amro

amro (view profile)

Answer by Amrinder Brar

Amrinder Brar (view profile)

on 25 Mar 2015 at 17:36
Edited by Amrinder Brar

Amrinder Brar (view profile)

on 25 Mar 2015 at 17:36

Is there any simple solution to this problem in iphone(i.e. without having to install any third party apps) ?

0 Comments

Amrinder Brar

Amrinder Brar (view profile)

Contact us