Saturday, April 28, 2018

Python 3.6.4 : Testing OpenCV default Hough Line Transform.

This tutorial is about Hough Line Transform and OpenCV python module.
This can be a good example for Hough Line Transform.
See the source code:
import cv2
import numpy as np
img = cv2.imread('test_lines.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# filter black and gray pixels
thresh = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY_INV)[1]

# find lines
lines = cv2.HoughLinesP(thresh, 1, np.pi/180,360,18)

# output lines onto image
for line in lines:
    x1,y1,x2,y2 = line[0]

# show image
cv2.imshow('threshold houghlines', img)
This is the result for : test_lines.jpg .

You can test by make changes into this line of code:
lines = cv2.HoughLinesP(thresh, 1, np.pi/180,360,18)
According with documentation the changes are influenced by the range parameters.

Friday, April 27, 2018

Python 3.6.4 : Testing the wit python module .

Today I tested the wit python module.
This python module is a Python library for
You can use for this issues:
  • Bots
  • Mobile apps
  • Home automation
  • Wearable devices
  • Robots
This support languages like:
Afrikaans, Albanian, Arabic, Azerbaijani, Bengali, Bosnian, Bulgarian, Burmese, Catalan, Central Khmer, Chinese, Croatian, Czech, Danish, Dutch, English, Estonian, Finnish, French, Georgian, German, Greek, Hausa, Hebrew, Hindi, Hungarian, Icelandic, Igbo, Indonesian, Inuktitut, Italian, Japanese, Kannada, Kinyarwanda, Korean, Latin, Latvian, Lithuanian, Macedonian, Malay, Maori, Mongolian, Norwegian, Persian, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Somali, Southern Ndebele, Southern Sotho, Spanish, Swahili, Swati, Swedish, Tagalog, Tamil, Thai, Tsonga, Tswana, Turkish, Ukrainian, Urdu, Uzbek, Venda, Vietnamese, Xhosa, Yoruba and Zulu.
About Wit is free, including for commercial use. So both private and public Wit apps are free and are governed our terms.
For this tutorial I use python 3.6.4 , see :
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]on win32
Type "help", "copyright", "credits" or "license" for more information.
The install of wit python module is simple:
C:\Python364>cd Scripts

C:\Python364\Scripts>pip install wit
Collecting wit
Successfully built wit
Installing collected packages: wit
Successfully installed wit-5.1.0

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]
 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from wit import Wit
>>> w=Wit('3ODKKNB---------')
>>> w.message('Python este un limbaj de programare')
{'_text': 'Python este un limbaj de programare', 'entities': {}, 'msg_id': '0pNT
>>> dir(w)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__form
at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_s
ubclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__',
 '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclas
shook__', '__weakref__', '_sessions', 'access_token', 'interactive', 'logger', '
message', 'speech']
>>> file = open('C:\Python364\hello_world.wav', 'rb')
>>> w.speech(file)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python364\lib\site-packages\wit\", line 88, in speech
    data=audio_file, headers=headers)
  File "C:\Python364\lib\site-packages\wit\", line 41, in req
    ' (' + rsp.reason + ')')
wit.wit.WitError: Wit responded with status: 400 (Bad Request)
The error has a open issue.
It does not seem to work properly.
There are some open issues for this python module.
The examples on the internet are not very concise with how to use this python module.