0

I'm trying to extract text from colored background images. One approach that I'm trying is edge detection. Using that I convert the original image to a image that I can work with. This will eliminate all the color in the image leaving only the edges.

I use this code to get the edged Image

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('messi5.jpg',0)
edges = cv2.Canny(img,100,200)

My problem is after I get these images how can I track the Letters in those images? Any help would be great. Thank you guys

These are the original and edge detected Images

Original Image

enter image description here

Edge Detected Image

enter image description here

  • 2
    That image is very graphic and might end up getting flagged as inappropriate. You might want to replace it with a less graphic image. This image shows the problem you want to solve but will likely offend or disturb a lot of users. – BHawk Jun 02 '17 at 17:20
  • So sorry. Didnt mean that. How about this one? – Tharindu Senanayake Jun 02 '17 at 17:32
  • Yes, that is much more palatable. Thank you. – BHawk Jun 02 '17 at 17:34

2 Answers2

3

Using edge detection on this image is premature, because the edges of the character will get polluted by the edges of the background.

Here is what you can get by selecting the pixels close to white:

enter image description here

Interestingly, many people who post about similar problems believe edge detection to be the panacea. In my opinion it is quite often a waste and region segmentation is much more appropriate.

1

You are at the beginning of a very long process involving concepts of computer vision and machine learning. There is too much to explain in a simple, concise answer here. However, there are a lot of good resources for doing this online (see below):

python: Simple Digit Recognition OCR in OpenCV-Python

c++: https://www.mkompf.com/cplus/emeocv.html

BHawk
  • 2,382
  • 1
  • 16
  • 24
  • 1
    Those two links aren't so helpful. They refer to cases where the characters are isolated on a clean background and the focus is on recognition, while the OP is clearly facing a problem of character extraction. –  Jun 04 '17 at 15:55
  • @BHawk learning img pro and combining with machine learning from the very basics, could you tell where to begin from? – Dev_Man Nov 08 '17 at 13:23
  • 1
    @Dev_Man I think a good place to start is the book: "Hands on machine learning with Scikit-learn and Tensorflow". It gives a good introductory overview of many different machine learning applications (image processing and otherwise) that you can code yourself. It also explains the math behind ML if you are inclined to learn it. – BHawk Nov 08 '17 at 16:38