Mobile camera as a webcam in MATLAB

lego car

Recently I bought this car and assembled it and I wanted to install wireless camera on top of that but I didn’t have wireless camera. I read in lifehacker that IP Webcam turns your Android phone into a wireless camera. So, the general solution would need two parts, one to broadcast the data from the device and another part to read this data into Matlab.

  • Install IP Webcam app from your mobile play store.
  • Open the app, tweak the settings (login/pass, resolution, image quality), set the desired resolution (will impact the speed!)
  • Scroll to the bottom and tap on ‘Start Server’
  • In the camera preview window, you can see the url at the bottom of the screen.
  • Open MATLAB and use below code 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.

mobile camera image

Continue reading

Background subtraction (Opencv Python)

Background subtraction is a major preprocessing steps in many vision based applications. For example, consider the cases like visitor counter where a static camera takes the number of visitors entering or leaving the room, or a traffic camera extracting information about the vehicles etc. In all these cases, first you need to extract the person or vehicles alone. Technically, you need to extract the moving foreground from static background.

BackgroundSubtractorMOG: It is a Gaussian Mixture-based Background/Foreground Segmentation Algorithm. It was introduced in the paper “An improved adaptive background mixture model for real-time tracking with shadow detection” by P. KadewTraKuPong and R. Bowden in 2001. It uses a method to model each background pixel by a mixture of K Gaussian distributions (K = 3 to 5). The weights of the mixture represent the time proportions that those colours stay in the scene. The probable background colours are the ones which stay longer and more static.

While coding, we need to create a background object using the function, cv2.createBackgroundSubtractorMOG(). It has some optional parameters like length of history, number of gaussian mixtures, threshold etc. It is all set to some default values. Then inside the video loop, use backgroundsubtractor.apply() (in my code fgbg.apply()) method to get the foreground mask. (read more about this function here)

Continue reading

Background subtraction

Background subtraction, also known as Foreground detection, is a technique in the fields of image processing and computer vision wherein an image’s foreground is extracted for further processing (object recognition etc.). Generally an image’s regions of interest are objects (humans, cars, text etc.) in its foreground. Background subtraction is a widely used approach for detecting moving objects in videos from static cameras. The rationale in the approach is that of detecting the moving objects from the difference between the current frame and a reference frame, often called “background image”, or “background model.

The basic method of background subtraction is to compare |frame – background| with
a pre-defined threshold (theta). If the difference of a pixel is larger than theta, then classify it as foreground; otherwise, claim that it is background.

(video dataset)

Continue reading

Absolute difference of two images

absolute difference of two images

absolute difference of two images

The pixel subtraction operator takes two images as input and produces as output a third image whose pixel values are simply those of the first image minus the corresponding pixel values from the second image. It is also often possible to just use a single image as input and subtract a constant value from all the pixels. Some versions of the operator will just output the absolute difference between pixel values, rather than the straightforward signed output.

I will use absolute difference of two images in the background subtraction in the next post 🙂

Continue reading

Choosing the right estimator

Often the hardest part of solving a machine learning problem can be finding the right estimator for the job because as we all know different estimators are better suited for different types of data and different problems.

The flowchart below is designed to give users a bit of a rough guide on how to approach problems with regard to which estimators to try on your data. (reference: (Read more))

Choosing the right estimator