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).
No products are associated with this question.
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:
url = 'http://<ip address>/shot.jpg'; ss = imread(url);
fh = image(ss); while(1) ss = imread(url); set(fh,'CData',ss); drawnow; end
(If you find faster ways/solutions for other devices, post it here!)
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
hVideoIn = vision.VideoPlayer('Name', 'Final Video'); while(1)
ss=imread(url); step(hVideoIn,ss) end
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
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