Thursday, June 13, 2013

Real Time Skin Detection In Video For Curbing Pornography on Web

Access to Porn in today's world is very easy. Keeping children out of reach of porn has become as difficult as keeping them away from candies. The parental lock and other control features provided in today's laptops and TVs are easy to pass by. What we need is an automatic control feature that detects the images and videos in real time and provides feedback to user regarding the content. We intend to make such a system. 


1. MATLAB R2010B


1. Load Video
2. Extract Frames
3. Detect Skin Regions and Take Decision

Step 1 : Load Video 

We begin with loading a video in MATLAB, start by creating a new .m file under the file menu in the editor window.

% Get Video 
obj = VideoReader('4.avi');

% Calculate Number of Frames

nFrames = obj.NumberOfFrames;

Note that in MATLAB R2009B you have to use mmreader() instead of VideoReader() since mmreader() has been discontinued or better renamed. If uploading only avi files you can even use aviread(). We intend to use multiple formats. The supported formats can be checked by typing in the command window the code below


This will return a list of supported formats

Video File Formats:
    .asf - ASF File
    .asx - ASX File
    .avi - AVI File
    .mj2 - Motion JPEG2000
    .mpg - MPEG-1

    .wmv - Windows Media Video

Step 2 : Extract Frames

for k = 1 : nFrames

img = read(obj,k);

The above code extracts one frame at a time and stores it in the variable 'img'. We then pre-process each frame to detect skin regions and then take decisive actions.

Step 3 : Detect Skin Regions and Take Decisions

The skin detection algorithm is pretty straight forward. 

Algorithm for Skin Detection in an Image :

1. GetRofimg, GetBofimg, GetGofimg
2. Calculate R-G and R-B
3. if R-G >= minskinthreshold1 && R-G <= maxskinthreshold1 && R-B  
   <=maxskinthreshold2 && R-B >= minskinthreshold2  then Goto 4
4. if skin region > = max(allowed) then blurred image
5. regular image (when 3 is false) 
6. increment frame
7. Goto  1

Thus using the above algorithm skin regions are detected in each frame and decisive action is also taken by checking the area of detected skin. 

Using the 'tic' and 'toc' routines in matlab, we found out that this method was faster than other detection techniques and yield better skin detection rate than other known techniques of skin detection.

Checkout the video of the project in action here...