title: How can I detect TV Screen from an Image with OpenCV or Another Library?
body: <p>I've working on this some time now, and can't find a decent solution for this.</p>
  
  <p>I use OpenCV for image processing and my workflow is something like this:</p>
  
  <ol>
  <li>Took a picture of a tv.</li>
  <li>Split image in to R, G, B planes - I'm starting to test using H, S, V too and seems a bit promising.</li>
  <li>For each plane, threshold image for a range values in 0 to 255</li>
  <li>Reduce noise, detect edges with canny, find the contours and approximate it.</li>
  <li>Select contours that contains the center of the image (I can assume that the center of the image is inside the tv screen)</li>
  <li>Use convexHull and HougLines to filter and refine invalid contours.</li>
  <li>Select contours with certain area (area between 10%-90% of the image).</li>
  <li>Keep only contours that have only 4 points.</li>
  </ol>
  
  <p>But this is too slow (loop on each channel (RGB), then loop for the threshold, etc...) and is not good enought as it not detects many tv's.</p>
  
  <p>My base code is the squares.cpp example of the OpenCV framework.</p>
  
  <p>The main problems of TV Screen detection, are:</p>
  
  <ol>
  <li>Images that are half dark and half bright or have many dark/bright items on screen.</li>
  <li>Elements on the screen that have the same color of the tv frame.</li>
  <li>Blurry tv edges (in some cases).</li>
  </ol>
  
  <p>I also have searched many SO questions/answers on Rectangle detection, but all are about detecting a white page on a dark background or a fixed color object on a contrast background.</p>
  
  <p>My final goal is to implement this on Android/iOS for near-real time tv screen detection. My code takes up to 4 seconds on a Galaxy Nexus.</p>
  
  <p>Hope anyone could help . Thanks in advance!</p>
  
  <p><strong>Update 1:</strong> Just using canny and houghlines, does not work, because there can be many many lines, and selecting the correct ones can be very difficult. I think that some sort of "cleaning" on the image should be done first.</p>
  
  <p><strong>Update 2:</strong> This <a href="https://stackoverflow.com/questions/10533233/opencv-c-obj-c-advanced-square-detection">question</a> is one of the most close to the problem, but for the tv screen, it didn't work.</p>