MATLAB Answers

Ashish Uthama

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

Asked by Ashish Uthama
on 20 Jul 2011
Latest activity Answered by saras
on 1 Jul 2016

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

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 ?


No products are associated with this question.

7 Answers

Answer by Ashish Uthama
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);
    ss  = imread(url);


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


set(fh, 'CData', rgb2gra(ss));

And be sure that you have done


after the original image() call.

on 22 Jul 2013

I'm using a GoPro HD camera which has a URL via an Ambarella video player as 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 "".

Current input in command window is url = ''; ss = imread(url); fh = image(ss);

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

Very nice Thank You!!

Answer by Chirag Gupta
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);
    ss  = imread(url);


Francisco, you'll get a better answer if you ask this as a new question:

(also look at for example)

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?

hi, please how can i save the video from this function? thank you best regard

Answer by amro
on 10 May 2014

    hVideoIn = vision.VideoPlayer('Name', 'Final Video');


This works well but i have question that why you did not use IP Camera Image Acquisition? i there any why to use it with ip webcam app

ipcam() was not introduced until R2015a, a year after amro posted their Answer.

Hi Hauder Ali, please can you explain how it work on IP camera Image Acquisition. I new in Matlab. thx

Answer by Amrinder Brar
on 25 Mar 2015
Edited by Amrinder Brar
on 25 Mar 2015

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

on 14 Sep 2015

Here's the working code for color detection using android camera:

url = ''; 
framesAcquired = 0;
while (framesAcquired <= 50)                   % the vedio will work till the 50 video frames, after that the vedio will stop. You can use while(1) for infinite loop
      data = imread(url); 
      framesAcquired = framesAcquired + 1;    
      diff_im = imsubtract(data(:,:,1), rgb2gray(data));  % subtracting red component from the gray image
      diff_im = medfilt2(diff_im, [3 3]);             % used in image processing to reduce noise and for filtering
      diff_im = im2bw(diff_im,0.18);                   % convert image to binary image
      stats = regionprops(diff_im, 'BoundingBox', 'Centroid');  % measures a set of properties for each connected component in the binary image
      hold on  
      for object = 1:length(stats)
          bb = stats(object).BoundingBox;
          bc = stats(object).Centroid;
          plot(bc(1),bc(2), '-m+')       
      hold off  
%stop(vid);    % to stop the video
%flushdata(vid);  % erase the data video
clear all

  1 Comment

hi PIYUSH KUMAR please this function it's just for a snaphot or video? i would like to have video and save it from my smarphone into matlab. how can I save directly as a AVI video? please help me. thank you

Answer by Soham Bhattacharyya on 16 May 2016

You can use DroidCam if you are using an android phone. You'll need to install OS Generic Video Interface driver.

Hope it helps. :)


Answer by saras
on 1 Jul 2016

I am not sure if this is exactly what you are looking for. However, you can use 'Simulink Support Package for Samsung GALAXY Android Devices' or 'Simulink Support Package for Apple iOS Devices' to access the appropriate smartphone camera. Both these support packages come with a Camera block that allow you to get the Camera data inside MATLAB. You can subsequently connect the Camera block to a Video Viewer block if you would like to visualize the data in Simulink.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!