Exemplo n.º 1
0
def detect_text_symbol(img, symbol_list):
    """
    Detects text in a list of symbols.
    
    Arguments:
        img {numpy.ndarray} -- Reference image
        symbol_list {list} -- List of coordinates of the symbols
    
    Returns:
        list -- List of dictionaries containing the coordinates of the symbols and the coordinates of text detected in symbols
    """
    try:
        ret = []
        for l in symbol_list:
            a, b, c, d = l[0].item(), l[1].item(), l[2].item(), l[3].item(),
            print(a)
            print(type(a))

            crop = img[b:d, a:c]
        
            lst = detect_text(img_in_memory=True, img=crop, img_name='temp_symbol')
            lt = []
            for t in lst:
                lt.append([int(t[0]) + l[0], int(t[1]) + l[1], int(t[2]) + l[2], int(t[3]) + l[3], t[4]])
            ret.append({'symbol':l, 'text':lt})

        return ret
    except:
        error_present = 1
        logging.error(' Error in detect_text_symbol function : ')
        error_message = PrintException()
        logging.error(error_message)
        raise
Exemplo n.º 2
0
def receipt_parse(image):

    preprocessed_image = preprocess(image)

    cv2.imwrite("temp.jpg", preprocessed_image)

    with io.open("temp.jpg", 'rb') as image_file:
        content = image_file.read()

    text_list = detect_text(content)

    if text_list == []:

        text_list = detect_text(image)

    information = parse_text(text_list)

    return information
def getRes(data, pic):
    result = {}
    # 3. crop pic using dimentions in template and save
    for key in data:
        coord = data[key]['coord']
        for i in range(len(coord)):
            coord[i] = int(coord[i] * pic.size[i % 2] / 100)

        temp = pic.crop((coord))
        temp.save('tmp.jpg', )

        # 4. send the cropped pic in detect_text
        text = detect_text('tmp.jpg')

        # 5. save the text in dict w key from template name
        result[key] = text.rpartition('\n')[2].lstrip()
    return result
Exemplo n.º 4
0
def main():
	bucket='itemstodetect'
	photo='cheetos.jpeg'
	#photo='abc.jpg'
	text=detect_text(photo,bucket)
	manywords = False
	combinewords = 1
	print(text)
	if text==None or len(text)<1:
		labels=detect_labels_local_file(photo,bucket)
		try:
			for i in labels:
				query = f"Amazon:{i[0]}"
				for j in search(query, tld="co.in",num=1,stop=1,pause=1):
					if j[0:22]!='https://www.amazon.com':
						continue
					print(i[0])
					print(j)
					webbrowser.open_new(j)
		except:
			print('Not found')
	else:
		try:
			if manywords:
				text = "Amazon:"+' '.join(text[0:combinewords])
				for j in search(text, tld="co.in",num=1,stop=1,pause=1):
						if j[0:22]!='https://www.amazon.com':
							continue
						print(j)
						#webbrowser.open_new(j)
			else:
				for i in text:
					query = f"Amazon:{i}"
					for j in search(query, tld="co.in",num=1,stop=1,pause=1):
						if j[0:22]!='https://www.amazon.com':
							continue
						print(i)
						print(j)
						webbrowser.open_new(j)
		except:
			print('Too many words')
Exemplo n.º 5
0
                        1] < 1010:  #center[1]>820 and center[1]<1010:     center[1]>366 and center[1]<447:
                    cv2.imwrite('images/outcam.jpg', image)
                    number_plate, score = number_detect('images/outcam.jpg')
                    if score is not None:
                        lis.append(number_plate)
                        lis1.append(score)
                        j = j + 1
                    cv2.circle(image, center, 10, (0, 0, 255), -1)
                    cv2.rectangle(image, (startX, startY), (endX, endY),
                                  COLORS[idx], 2)
                if center[1] > 1010 and len(lis) != 0 and len(lis1) != 0:
                    s = datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S')
                    img_path = lis[lis1.index(max(lis1))]
                    path = 'number_plate/image' + str(j) + '.jpg'
                    cv2.imwrite(path, img_path)
                    number_string = detect_text(path)
                    #print(number_string)
                    data = {
                        "vehicle": {
                            "out_time": s,
                            "number_plate": number_string,
                        }
                    }
                    r = requests.put(url=API_ENDPOINT, json=data)
                    del (lis[:])
                    del (lis1[:])

    #cv2.imshow('vid3',image)
    #if cv2.waitKey(30) and 0xFF==ord('q'):
    #	break
Exemplo n.º 6
0
    return information


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('input_file', help='The image for text detection.')
    args = parser.parse_args()

    preprocessed_image = preprocess(args.input_file)

    cv2.imwrite("temp.jpg", preprocessed_image)

    #work on changing this later ^^^

    with io.open("temp.jpg", 'rb') as image_file:
        content = image_file.read()

    text_list = detect_text(content)

    if text_list == []:

        with io.open(args.input_file, 'rb') as image_file:
            content = image_file.read()

        text_list = detect_text(content)

    information = parse_text(text_list)

    print(information)