sentago
sentago

Reputation: 11

Text Detection on the Label

I am a new member. I’m interested in OpenCV. I want to detect text on the label on a bottle. I tried color filtering but was not successful. Sample label;

Text - LightShot SS

No Text - LightShot SS

Also the code i use.

import cv2  import numpy as np  

cap = cv2.VideoCapture(0)  

while(1):        
    _, frame = cap.read()  
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 
    lower_red = np.array([110,50,50]) 
    upper_red = np.array([130,255,255]) 
    mask = cv2.inRange(hsv, lower_red, upper_red) 
    res = cv2.bitwise_and(frame,frame, mask= mask) 
    cv2.imshow('frame',frame) 
    cv2.imshow('mask',mask) 
    cv2.imshow('res',res) 
    k = cv2.waitKey(5) & 0xFF
    if k == 27: 
        break

cv2.destroyAllWindows()  cap.release()

I’m using NVIDIA Jetson Nano 4GB. I’m waiting for your help. Thank you all in advance.

Upvotes: 0

Views: 305

Answers (1)

Kedar17
Kedar17

Reputation: 200

import pytesseract    #### Read this library documentation before running it 

import cv2
from PIL import Image

# pytesseract.pytesserct.image_to_string()
pytesseract.pytesseract.tesseract_cmd = r'C:\XXXX\XXXXXX\XXXX\XXXX\XXXXX\Tesseract-OCR\tesseract.exe'
img = cv2.imread('Text_entropy.png')

himg, wimg, vimg = img.shape
boxes = pytesseract.image_to_boxes(img)
for b in boxes.splitlines():
#     print(b)
    b = b.split(' ')
#     print(b)
    x, y, w, h = int(b[1]), int(b[2]), int(b[3]), int(b[4])
    cv2.rectangle(img, (x,himg-y), (w, himg-h), (0, 0, 255), 1)
    cv2.putText(img, b[0], (x, himg-y+30), cv2.FONT_HERSHEY_COMPLEX, 1, (50, 50, 255), 1)
    
cv2.imshow('Result', img)


cv2.waitKey(0)

Hope This code will help youenter image description here

Upvotes: 1

Related Questions