Home How to do automatic recognition of height of text and distance between words?
Reply: 0

How to do automatic recognition of height of text and distance between words?

user3160 Published in July 23, 2018, 1:24 pm

I want to write a script which automaticly will recognize height of text and distance between two words - for analysing personality. I wrote script which does this but manualy:


main script (i know that isn't a best code ever)

import cv2
import numpy as np
from scipy.spatial import distance
from dist_analyzer import DistAnalyzer


def pointer(event, x, y, flags, param):
    global point, dist, ratio
    if event == cv2.EVENT_LBUTTONDOWN:
         point.append((x, y))

    if len(point) == 2:
         a = point[0]
         b = point[1]
         dist = distance.euclidean(a, b)
         ratio = dist/text

         print DistAnalyzer.analyze(ratio)

def onChange(pos):
     global img, gray, dst, text

     dst = np.copy(img)
     top = cv2.getTrackbarPos("Top", "test")
     bottom = cv2.getTrackbarPos("Bottom", "test")

     cv2.line(dst,(0, bottom),(20000, bottom),(255,0,0),1)
     cv2.line(dst,(0, top),(20000, bottom),(255,0,0),1)

     text = bottom - top

if __name__ == "__main__" :

img = cv2.imread("well_balanced.jpg", -1)
dst = np.copy(img)
cv2.namedWindow("test", cv2.WINDOW_AUTOSIZE)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.createTrackbar("Top", "test", 0, len(gray), onChange)
cv2.createTrackbar("Bottom", "test", 50, len(gray), onChange)
cv2.setMouseCallback("test", pointer)

while True:
        cv2.imshow("test", dst)
        key = cv2.waitKey(1)
        if key == ord('q'):



additional script for analyze personality based on ratio of height and distance between two words.

class DistAnalyzer:

    def analyze(ratio):

        if ratio<0.1:
            return {
                "spacing": "verry narrow",
                "analysis": "someone who will crowd others for attention, craving          constant contact and closeness"

        if ratio>1.9:
            return {
                "spacing": "verry wide",
                "analysis": "someone who need maintain his distance from social contact, either due to an inner need for privacy."

        if ratio>0.1 and ratio<0.7:
            return {
                "spacing": "narrow letters with cramped spacing",
                "analysis": "someone who is fearful and dependent, who cannot give himself (or others) enough space in life"

        if ratio>1.4 and ratio<1.9:
                return {
                "spacing": "wide letters with wide spaces",
                "analysis": "someone who demands attention in an extravagant or exaggerated manner, stemming from a need to be noticed"
        if ratio>0.9 and ratio<1.4:
            return {
                "spacing": "well-balanced",
                "analysis": "someone who is social maturity, intelligence and inner organization"

How to automate this script? Any advices?

Thank you in advance

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.739658 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO