title: Detecting if image is a cartoon or if it is a real person with OpenCV
body: <p>I am trying to detect if an image is a cartoon or if it is a real person.  I have searched Google and implemented two algorithms mentioned, but neither can accurately predict if an image is a person taken by a camera or if it is a cartoon/anime character</p>
  
  <p>Here is my script:</p>
  
  <p>detectCartoon1 uses the Laplacian method to detect if an image is a person or not.  (I figured camera shots would be lower quality and thus this would easily work).  But it fails- it gives me tons of false positives.</p>
  
  <p>detectCartoon2 uses a method mentioned by someone else on stack overflow.  It figures that after we apply the filter to the cartoon, there won't be many changes; but there will be a lot of changes if we apply a picture taken from a lower quality camera/webcam.  Again, tons of false positives.</p>
  
  <p>I've been searching around Google for other methods- or trying to think of my own method, but I just can't think of anything.  I would greatly appreciate any help on this topic.</p>
  
  <p>Thanks!</p>
  
  <pre><code>import cv2
  import numpy
  
  def detectCartoon1(imagePath):
      img_before = cv2.imread(imagePath)
      img_after = 0    
  
      gray = cv2.GaussianBlur(img_before, (3, 3), 0, 0, cv2.BORDER_DEFAULT)
      gray = cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)
      img_after = cv2.Laplacian(gray, cv2.CV_64F)
      img_after = cv2.convertScaleAbs(img_after)
  
      return numpy.mean(img_after)    
  
  def detectCartoon2(imagePath):
      img_before = cv2.imread(imagePath)
      img_after = 0
  
      for i in range(1, 31, 2):
          img_after = cv2.bilateralFilter(img_before, i, i*2, i/2)
  
      img_after = cv2.cvtColor(img_after, cv2.COLOR_HSV2BGR_FULL)
      img_before = cv2.cvtColor(img_before, cv2.COLOR_HSV2BGR_FULL)
  
      return numpy.mean(img_before - img_after)
  
  from os import listdir
  
  for img in listdir('Save'):
      img = 'Save\\' + img
      dc1 = detectCartoon1(img)
      dc2 = detectCartoon2(img)
      print('Img: ' + img + ' detectCartoon1: ' + str(dc1) + ' detectCartoon2: ' + str(dc2))
  </code></pre>