I am trying to create a python script to extract gas price information from gas station totems. I'm thinking about using number recognition that is built in opencv-python, but firstly I need to somehow extract the totem from the picture itself.
For example, from this image: Benzina gas tation totem with red prices img
The output would be something like:
- Diesel - 32.20
- Gas 95 - 32.20
- LPG - 13.90
It's fine to ignore the extra offers, like the blue "Verva Diesel" and such. I'm thinking that the best way to know what the offer is, is to find the square next to the price and average it's color. Green being gas, black being diesel and yellow being LPG. Those colors are the de facto standard in my country.
I have tried using cv2.findContours
and cv2.Canny
to preprocess the image. I still haven't figured out how to extract the rectangle containing the whole totem or the rectangles that contain the prices themselves.
Here's what I've figured out until now:
import cv2
import numpy as np
src = cv2.imread("media/totem1.jpeg")
src2 = src.copy()
cv2.imshow("original", src)
gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray, 100 , 250 ,0)
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(src, [c], -1, (0, 255, 0), 1)
cv2.imshow("findContours", src)
edges = cv2.Canny(gray ,100,200)
cv2.imshow("Canny", edges)
I've also tried using HoughLines
, but I wasn't able to get any decet results even with tweaking the settings.
Here's the output of that: