EDIT . I wrote a Python script for this.
Since your goal is blurring (to protect privacy), you first need a high recall detector. Here's how to do it. The code hints introduced use OpenCV with Python.
- Convert to shades of gray.
Apply Gaussian Blur.
img = cv2.imread('input.jpg',1) img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img_gray = cv2.GaussianBlur(img_gray, (5,5), 0)
Let the input image be as follows.

- Apply a Sobel filter to identify vertical edges.
Threshold of the resulting image using strict threshold or OTSU binarization.
cv2.Sobel(image, -1, 1, 0) cv2.threshold()
Apply a morphological closure operation using a suitable structural element. (I used 16x4 as a structuring element)
se = cv2.getStructuringElement(cv2.MORPH_RECT,(16,4)) cv2.morphologyEx(image, cv2.MORPH_CLOSE, se)
The resulting image after step 5.

Find the outer contours of this image.
cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
For each path, find minAreaRect() to bound it.
- Select rectangles based on aspect ratio, minimum and maximum area, and horizontal angle. (I used 2.2 <= Aspect Ratio <= 8, 500 <= Area <= 15000 and angle <= 45 degrees).
All minAreaRect() are shown in orange, and the value that matches our criteria is green.

- After this step, there may be false positives to filter it, use the edge density. Edge Density is defined as the number of white pixels / total number of pixels in the rectangle. Set the edge density threshold. (I used 0.5)

- Blur detected areas.

You can apply other filters that you think are appropriate to increase the number of reminders and accuracy. Detection can also be trained using HOG + SVM to improve accuracy.
Abdul Fatir May 30 '16 at 10:35 a.m. 2016-05-30 10:35
source share