MATLAB Answers

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

290 ビュー (過去 30 日間)
Ashish Uthama
Ashish Uthama 2011 年 7 月 20 日
コメント済み: surya ningsih 2021 年 3 月 24 日
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 件のコメント
Sarah Mahmood
Sarah Mahmood 2013 年 6 月 3 日
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 2011 年 7 月 20 日
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!)
  13 件のコメント
surya ningsih
surya ningsih 2021 年 3 月 24 日
thank you very much

サインインしてコメントする。

その他の回答 (14 件)

Soham Bhattacharyya
Soham Bhattacharyya 2016 年 5 月 16 日
You can use DroidCam if you are using an android phone. You'll need to install OS Generic Video Interface driver.
Hope it helps. :)
  2 件のコメント
Nikhil Sai
Nikhil Sai 2018 年 2 月 7 日
thank you worked for me

サインインしてコメントする。


Chirag Gupta
Chirag Gupta 2011 年 7 月 20 日
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
  5 件のコメント
Tiwa Romuald
Tiwa Romuald 2015 年 10 月 15 日
hi, please how can i save the video from this function? thank you best regard

サインインしてコメントする。


amro
amro 2014 年 5 月 10 日
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
  3 件のコメント
Tiwa Romuald
Tiwa Romuald 2015 年 10 月 8 日
Hi Hauder Ali, please can you explain how it work on IP camera Image Acquisition. I new in Matlab. thx

サインインしてコメントする。


PIYUSH KUMAR
PIYUSH KUMAR 2015 年 9 月 14 日
Here's the working code for color detection using android camera:
url = 'http://192.168.0.100:8080/shot.jpg';
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
drawnow;
imshow(data);
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','b','LineWidth',2)
plot(bc(1),bc(2), '-m+')
end
hold off
end
%stop(vid); % to stop the video
%flushdata(vid); % erase the data video
clear all
  1 件のコメント
Tiwa Romuald
Tiwa Romuald 2015 年 10 月 14 日
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

サインインしてコメントする。


Siddhant Baral
Siddhant Baral 2018 年 2 月 7 日
url = "http: // IP /shot.jpg '; ss = imread (url); fh = imagen (ss); mientras que (1) ss = imread (url); conjunto (FH, 'programable CData', ss); drawNow; fin

Amrinder Brar
Amrinder Brar 2015 年 3 月 25 日
編集済み: Amrinder Brar 2015 年 3 月 25 日
Is there any simple solution to this problem in iphone(i.e. without having to install any third party apps) ?

saras
saras 2016 年 7 月 1 日
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.
  1 件のコメント
Deepak B
Deepak B 2020 年 9 月 16 日
actuallty im looking for this can we send live camera video from the android device i installed the simulink support package for android
but i dont know hoe to use that to send live video to matkab simulink help me out

サインインしてコメントする。


Cristian David Jimenez Bedoya
Cristian David Jimenez Bedoya 2016 年 12 月 5 日
編集済み: Walter Roberson 2016 年 12 月 5 日
buenas, este programa funciona bien pero no he logrado capturar una imagen a partir de este mismo, como puedo obtener una captura de imagen y almacenarla ?
url = "http: // <dirección IP> /shot.jpg ';
ss = imread (url);
fh = imagen (ss);
mientras que (1)
ss = imread (url);
conjunto (FH, 'programable CData', ss);
drawNow;
fin
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 12 月 5 日
imwrite() the content of ss

サインインしてコメントする。


MARIA JAVED
MARIA JAVED 2017 年 2 月 4 日
can anybody tell me that how we can do face detection through Android phone pls help??? i need that code?
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 6 日
You would either have to write the code in MATLAB and use MATLAB Coder, or else you would have to create a Simulink model and deploy that to Android.

サインインしてコメントする。


Jonathan berry
Jonathan berry 2017 年 4 月 10 日
Hello guys,
I keep having this error:
Error using imread (line 350) Can't read URL "http://MY_IP /shot.jpg".
any help will be appreciated
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 29 日
You need to replace he "MY_IP " part by your actual IP address, such as http://192.168.0.10/shot.jpg

サインインしてコメントする。


Dilip Dubey
Dilip Dubey 2018 年 4 月 29 日
How can I read other sensors from IP webcam app in Matlab?
  1 件のコメント
vass pass
vass pass 2020 年 7 月 23 日
You can geet a json file for sensors
s='4'
urlImage=['http://192.168.1.' s ':8080/shot.jpg']
urlSensors=['http://192.168.1.' s ':8080/sensors.json']
frame = imread(urlImage);
q=jsondecode(urlread(urlSensors)); %#ok<URLRD>
q.accel.data{1}{2}

サインインしてコメントする。


Beril Sirmacek
Beril Sirmacek 2018 年 4 月 29 日
Hi All,
I found out that;
imread('http://MY_IP /shot.jpg');
works only on secured network for me. If I am on a public network, then it gives error.
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 6 日
"On Windows platforms, this parameter supports URLs that point to MMS (Microsoft Media Server) streams."

サインインしてコメントする。


keerthana potharaj
keerthana potharaj 2019 年 1 月 29 日
how do we interface mobile camera for deep learning?
P.S we don't have web cam. pls help us.

kundan surse
kundan surse 2020 年 1 月 21 日
I want to take the screenshot of my mobile screen form matlab to use it for further prossesing how can i do that ?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by