Login
main >   ml_per_pixel_char >  


#!/usr/bin/env python
"""
Triangle Point:
https://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle
"""
import sys

import cv2
import numpy as np


def find_next_char(img, w, h, point):
    found_pixel = False
    for x in range(point[0], w):
        for y in range(h):
            if img[y, x] < 170:
                return (x, y)


def draw_triangle(img, p1, p2, p3):
    #img = np.zeros((512,512,3), np.uint8)
    #cv2.line(img,(0,0),(511,511),(255,0,0),5)


    img = cv2.line(img,p1,p2,(237,237,52),1) #Yellow
    img = cv2.line(img,p1,p3,(34,189,44),1) #Green

    return(img)

def next_pixel(img, point):
    h, w = img.shape
    
    if point[1] == h - 1:
        if point[0] != w - 1:
            point[0] += 1
            point[1] = 0
    else:
        point[1] += 1

    return point


def sign(p1, p2, p3):
    return((p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]))


def point_in_triangle(pt, v1, v2, v3):
    d1 = sign(pt, v1, v2)
    d2 = sign(pt, v2, v3)
    d3 = sign(pt, v3, v1)

    has_neg = (d1 < 0) or (d2 < 0) or (d3 < 0)
    has_pos = (d1 > 0) or (d2 > 0) or (d3 > 0)

    return(not (has_neg and has_pos))


class Get_N:
    def __init__(self):
        return


if __name__ == '__main__':

    cv2.namedWindow('image', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('image', 600,600)

    word = 'NomFAkAZo'

    img = cv2.imread('string.jpg')
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    point = [0, 0]
    #print(img.shape)

    word_progress = ''

    #Triangle
    p1 = (0, 0)
    p2 = (150, 12)
    p3 = (5, 10)

    while True:
#        if word_progress != word:
#            get_char

        point = next_pixel(gray_image, point)

        progress_img = img.copy()
        print(progress_img.shape)
        progress_img = draw_triangle(progress_img, p1, p2, p3)

        if gray_image[point[1], point[0]] < 170:
            if point_in_triangle(point, p1, p2, p3):
                img[point[1], point[0]] = [255, 72, 198]

        progress_img[point[1], point[0]] = [0, 72, 198]

        cv2.imshow('image',progress_img)
        if cv2.waitKey(10) & 0xFF == ord('q'):
            break
        


    cv2.destroyAllWindows()
hidden1

hidden2