---
# System prepended metadata

title: RGA Blog Draft

---

# RGA Blog Draft

## Introduction
If you have ever been to the Times Square in New York City(or seen it in pictures), you will quite literally be "surrounded" by countless advertisements from corporate companies and startups alike. Did you ever wonder how the brands make sure the advertisements meet their rules and regulations? Well, there are a zillion intricate rules governing the placement of every piece of text, every pixel of an image to ensure that any form of advertisement is consistent and is following legal regulations. 



1. Convert pdf's and png to jpg using Ghostscript
    a. The wellknown python libraries to convert pdf's to jpg are not compatible with training on AI Platform so to overcome this Ghostscript library was used.
    b. Our trained neural net model for Logo detection is compatible with JPG file extensions, so the need to convert every filetype extension to JPG was there.
    c. For more info - https://www.activestate.com/blog/using-python-to-convert-pdfs-to-images/
    
2. Enhancing the image quality.
    a. The conversion of pdf to jpg was resulting in a lesser PPI(Pixels per inch) which was affecting the performance of OCR in a negative manner.
    b. PIL library was used to increase the PPI.
    
3. Training siamese neural net
    a. The main objective of the model was to measure the correctness of the Logo design with brand approved Logo designs.
    b. One shot learning was identified as the ideal way to approach the problem because of a definite number of different logo designs, so siamese neural net was selected as the model type.
    c. Siamese neural net doesn't provide probability of each class as one of its output, so K-Means algorithm was developed on top of the neural net to generate probabilities for each class. 
    For more info - https://towardsdatascience.com/a-friendly-introduction-to-siamese-networks-85ab17522942
    
4. Detecting horizontal lines
    a. The use case required horizontal lines spread over the whole width of the page to be detected for some further enhancements.
    b. To detect the horizontal lines, input image was converted to grayscale image and HoughLines method and some morphological operations(erode and dilate) provided by OpenCV library were performed.
    
5. Detecting inverted images
    a. Based on the OCR response by Google Vision API, if the x-coordinates for a word are in decreasing order then it implies that the text is inverted. 