Re: how to automate java application in window using python

2016-09-16 Thread meInvent bbird
On Friday, September 16, 2016 at 2:26:47 AM UTC+8, [email protected] wrote:
> On Thursday, September 15, 2016 at 8:13:05 AM UTC+1, meInvent bbird wrote:
> > how to automate java application in window using python
> > 
> > 1. scroll up or down of scroll bar
> > 2. click button
> > 3. type text in textbox
> 
> Please read this http://www.catb.org/esr/faqs/smart-questions.html and then 
> this http://sscce.org/ and then rephrase your post.
> 
> Kindest regards.
> 
> Mark Lawrence.

i find this, but it is not python, it is a product

http://sqa.stackexchange.com/questions/18134/python-based-test-automation-tools-for-desktop-applications
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-16 Thread Lawrence D’Oliveiro
On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird wrote:
> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence D’Oliveiro
> wrote:
>> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent bbird
>> wrote:
>>> how to automate java application in window using python
>>> 
>>> 1. scroll up or down of scroll bar
>>> 2. click button
>>> 3. type text in textbox
>> 
>> Well, don’t leave us in suspense! Give us the link to your blog post!
> 
> i do not have blog post, 

Oh, now you make us sad. I thought you were promoting a blog post where you 
tell us “how to automate java application in window using python” using just 3 
steps! But it turns out you have nothing. You are an empty promiser.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Requests for webbrowser module

2016-09-16 Thread Jamie Ansell
Thanks for your help, I realise that what I wanted was chromes default new
tab page, not a blank page. 'about:blank' worked fine but it wasn't what I
wanted sorry. I'll try the CTRL+4 later and see it that works.

On 14 Sep 2016 21:11, "John Gordon"  wrote:

> In  Jamie <
> [email protected]> writes:
>
> > I am not sure if this is an intended consequence but when using the
> > webbrowser module to open a new blank browser tab in chrome it opens it
> > in a new browser window instead of using the current window. Providing
>
> There is an internal setting within Chrome that controls whether new pages
> are opened in a new tab or a new window.  Perhaps that is your issue?
>
> --
> John Gordon   A is for Amy, who fell down the stairs
> [email protected]  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Expected type 'optional[bytes]' got 'str' instead

2016-09-16 Thread Peter Otten
> Daiyue Weng wrote:

[Please answer to the mailing list instead of sending private emails]

> On 13 September 2016 at 12:37, Peter Otten <[email protected]> wrote:
>> Daiyue Weng wrote:
>>> Hi, I have the following piece of code,
>>> 
>>> rootPath = os.path.abspath(__file__)
>>> 
>>> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0]
>>> 
>>> 
>>> PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit,
>>> 
>>> Expected type 'optional[bytes]' got 'str' instead
>>> 
>>> 
>>> If I changed it to,
>>> 
>>> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit(b'\\', 1)[0]
>>> 
>>> Python game me errors,
>>> 
>>> TypeError: Can't convert 'bytes' object to str implicitly
>>> 
>>> How to fix it?
>> 
>> Do you use Python 2 or 3?
>> 
>> Is your version the one PyCharm expects and supports? If yes, consider
>> filing a bug report (for PyCharm, not Python).
>> 
>> You should of course still follow Chris' advice and use os.path to
>> manipulate file paths.

> Hi, I am using Python 3.5.1 on PyCharm. Is it a bug in PyCharm?

I think it is.

-- 
https://mail.python.org/mailman/listinfo/python-list


Find Nested group in LDAP by this i mean group in group

2016-09-16 Thread Robert Clove
Hi,

I was looking for search query in LDAP for nested group memebership.
It would be great if someone can provide the python code for the same.

Regards
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-16 Thread Christian Gollwitzer

Am 16.09.16 um 09:01 schrieb Lawrence D’Oliveiro:

On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird
wrote:

On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence
D’Oliveiro wrote:

On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent
bbird wrote:

how to automate java application in window using python

1. scroll up or down of scroll bar 2. click button 3. type text
in textbox


Well, don’t leave us in suspense! Give us the link to your blog
post!


i do not have blog post,


Oh, now you make us sad. I thought you were promoting a blog post
where you tell us “how to automate java application in window using
python” using just 3 steps! But it turns out you have nothing. You
are an empty promiser.


You are being mean. It is quite evident that English is not his first 
language, and highly probable that this was actually the question "How 
do I automate a Java application using Python?"


I don't have a real answer myself, but maybe using Jython one can get 
access to the Java objects underlying the application (and then, of 
course, execute methods of the GUI objects). This depends on the GUI 
toolkit (Swing/SWT) and knowledge of the applications' structure, of 
course. Another (less robust) way of desktop automation is Sikuli 
http://www.sikuli.org/ (Windows only, I think)


Christian

--
https://mail.python.org/mailman/listinfo/python-list


why this code loop forever after a draw a rectangle

2016-09-16 Thread meInvent bbird
im = img.copy()
cntcounter = 0
for cnt in contours:
epsilon = 0.1*cv2.arcLength(cnt,True)
approx = cv2.approxPolyDP(cnt,epsilon,True) 
#peri = cv2.arcLength(cnt, True)
#approx = cv2.approxPolyDP(c, 0.5 * peri, True)
#print("len(approx)="+str(len(approx)))
if len(approx) == 4:
print("approx=" + str(approx))
cntcounter = cntcounter + 1
print("here1")
x,y,w,h = cv2.boundingRect(cnt)
print("here2")
while im is None:
time.sleep(1)
if im is not None:
print("here3")
im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)  
   
#im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
#im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
#im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
#im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)


cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)
-- 
https://mail.python.org/mailman/listinfo/python-list


Discover all non-standard library modules imported by a script

2016-09-16 Thread Malcolm Greene
Looking for suggestions on how, given a main script, discover all the
non-standard library modules imported across all modules, eg. the
modules that other modules import, etc. I'm not looking to discover
dynamic imports or other edge cases, just the list modules loaded via
"import " and "from  import ...". I know I could write a
script to do this, but certainly there must be such a capability in the
standard library?

Use case: Discovering list of modules to use for building a Python 3.5
zipapp distributable.

Thank you,
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread Joonas Liik
On 16 September 2016 at 14:24, meInvent bbird  wrote:
> im = img.copy()
> cntcounter = 0
> for cnt in contours:
> epsilon = 0.1*cv2.arcLength(cnt,True)
> approx = cv2.approxPolyDP(cnt,epsilon,True)
> #peri = cv2.arcLength(cnt, True)
> #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
> #print("len(approx)="+str(len(approx)))
> if len(approx) == 4:
> print("approx=" + str(approx))
> cntcounter = cntcounter + 1
> print("here1")
> x,y,w,h = cv2.boundingRect(cnt)
> print("here2")
> while im is None:
> time.sleep(1)
> if im is not None:
> print("here3")
> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)
>
>
> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)
> --
> https://mail.python.org/mailman/listinfo/python-list

not sure but..  this bit reads really suspicious:

while im is None:
time.sleep(1)

if im is ever None then how will it ever become not None? unless there
is some other thread at work i can't really see this happening.
and if there is some other thread at work then there is probably some
better solution than sleep()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Discover all non-standard library modules imported by a script

2016-09-16 Thread Chris Angelico
On Fri, Sep 16, 2016 at 9:29 PM, Malcolm Greene  wrote:
> Looking for suggestions on how, given a main script, discover all the
> non-standard library modules imported across all modules, eg. the
> modules that other modules import, etc. I'm not looking to discover
> dynamic imports or other edge cases, just the list modules loaded via
> "import " and "from  import ...". I know I could write a
> script to do this, but certainly there must be such a capability in the
> standard library?
>
> Use case: Discovering list of modules to use for building a Python 3.5
> zipapp distributable.
>

Possibly not what you're thinking of, but try creating a clean virtual
environment (python3 -m venv env) and installing no packages, and then
watch for ImportError. As you find them, record stuff into
requirements.txt and "pip install -r requirements.txt", until you have
a working program - at which point requirements.txt should have every
non-standard thing you're using.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread meInvent bbird
i follow this post to give some time it to operate,
wait a long time still looping

http://answers.opencv.org/question/60094/libpng-warning-image-width-is-zero-in-ihdr/


i can not stand this Ninja coding life any more,
i have to open my code for ask this error


import cv2
import numpy as np
#from matplotlib import pyplot as plt
import time

#print("1=" + str(int(sys.argv[1])))
#print("2=" + str(int(sys.argv[2])))
#print("3=" + str(int(sys.argv[3])))

img_rgb = cv2.imread(r'C:\Users\martin\Documents\scree2.png')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(r'C:\Users\martin\Documents\dragob.png',0)
w, h = template.shape[::-1]

res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.64

loc = np.where( res >= threshold)
pt = [(0,0)]

while not zip(*loc[::-1]):
threshold = threshold - 0.02
loc = np.where( res >= threshold)

counter = 1
print("threshold="+str(threshold))   
for pt2 in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt2, (pt2[0] + w, pt2[1] + h), (0,0,255), 2)
pt = pt2
crop_img = img_rgb[pt[1]:(pt[1]+h), pt[0]:(pt[0]+w)]
counter = counter + 1

cv2.imwrite("C:\\Users\\tester\\Documents\\res.png",crop_img)


#import cv2
#winName = "Movement Indicator"
#cv2.namedWindow(winName, cv2.WINDOW_NORMAL)
img = cv2.imread(r'C:\Users\tester\Documents\res.png',1)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
height, width = gray.shape
edges = cv2.Canny(gray,height,width,apertureSize = 3)
#edges = cv2.Canny(gray,30,200)

#gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
#ret,thresh = 
cv2.threshold(edges.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE,0)
ret,thresh = cv2.threshold(edges,250,150,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
#contours = sorted(contours, key = cv2.contourArea, reverse = True)[:10]

im = img.copy()
cntcounter = 0
for cnt in contours:
epsilon = 0.1*cv2.arcLength(cnt,True)
approx = cv2.approxPolyDP(cnt,epsilon,True) 
#peri = cv2.arcLength(cnt, True)
#approx = cv2.approxPolyDP(c, 0.5 * peri, True)
#print("len(approx)="+str(len(approx)))
if len(approx) == 4:
print("approx=" + str(approx))
cntcounter = cntcounter + 1
print("here1")
x,y,w,h = cv2.boundingRect(cnt)
print("here2")
#im = img.copy()
while im is None:
time.sleep(1)
if im is not None:
print("here3")
im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) 

#cv2.imwrite("C:\\Users\\martin\\Documents\\masda"+str(cntcounter)+".png",imi)  
  
#im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
#im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
#im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
#im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)








On Friday, September 16, 2016 at 7:34:04 PM UTC+8, Waffle wrote:
> On 16 September 2016 at 14:24, meInvent bbird  wrote:
> > im = img.copy()
> > cntcounter = 0
> > for cnt in contours:
> > epsilon = 0.1*cv2.arcLength(cnt,True)
> > approx = cv2.approxPolyDP(cnt,epsilon,True)
> > #peri = cv2.arcLength(cnt, True)
> > #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
> > #print("len(approx)="+str(len(approx)))
> > if len(approx) == 4:
> > print("approx=" + str(approx))
> > cntcounter = cntcounter + 1
> > print("here1")
> > x,y,w,h = cv2.boundingRect(cnt)
> > print("here2")
> > while im is None:
> > time.sleep(1)
> > if im is not None:
> > print("here3")
> > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 
> > 2)
> > #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
> > #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
> > #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
> > #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)
> >
> >
> > cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> not sure but..  this bit reads really suspicious:
> 
> while im is None:
> time.sleep(1)
> 
> if im is ever None then how will it ever become not None? unless there
> is some other thread at work i can't really see this happening.
> and if there is some other thread at work then there is probably some
> better solution than sleep()





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-16 Thread meInvent bbird
you are right, english is not my first language

i just talk as simple as i can, i do not know previous talking is mean


On Friday, September 16, 2016 at 6:22:34 PM UTC+8, Christian Gollwitzer wrote:
> Am 16.09.16 um 09:01 schrieb Lawrence D’Oliveiro:
> > On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird
> > wrote:
> >> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence
> >> D’Oliveiro wrote:
> >>> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent
> >>> bbird wrote:
>  how to automate java application in window using python
> 
>  1. scroll up or down of scroll bar 2. click button 3. type text
>  in textbox
> >>>
> >>> Well, don’t leave us in suspense! Give us the link to your blog
> >>> post!
> >>
> >> i do not have blog post,
> >
> > Oh, now you make us sad. I thought you were promoting a blog post
> > where you tell us “how to automate java application in window using
> > python” using just 3 steps! But it turns out you have nothing. You
> > are an empty promiser.
> 
> You are being mean. It is quite evident that English is not his first 
> language, and highly probable that this was actually the question "How 
> do I automate a Java application using Python?"
> 
> I don't have a real answer myself, but maybe using Jython one can get 
> access to the Java objects underlying the application (and then, of 
> course, execute methods of the GUI objects). This depends on the GUI 
> toolkit (Swing/SWT) and knowledge of the applications' structure, of 
> course. Another (less robust) way of desktop automation is Sikuli 
> http://www.sikuli.org/ (Windows only, I think)
> 
>   Christian

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-16 Thread Fabio Zadrozny
Take a look at https://pyautogui.readthedocs.io/en/latest/

On Fri, Sep 16, 2016 at 9:24 AM, meInvent bbird 
wrote:

> you are right, english is not my first language
>
> i just talk as simple as i can, i do not know previous talking is mean
>
>
> On Friday, September 16, 2016 at 6:22:34 PM UTC+8, Christian Gollwitzer
> wrote:
> > Am 16.09.16 um 09:01 schrieb Lawrence D’Oliveiro:
> > > On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird
> > > wrote:
> > >> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence
> > >> D’Oliveiro wrote:
> > >>> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent
> > >>> bbird wrote:
> >  how to automate java application in window using python
> > 
> >  1. scroll up or down of scroll bar 2. click button 3. type text
> >  in textbox
> > >>>
> > >>> Well, don’t leave us in suspense! Give us the link to your blog
> > >>> post!
> > >>
> > >> i do not have blog post,
> > >
> > > Oh, now you make us sad. I thought you were promoting a blog post
> > > where you tell us “how to automate java application in window using
> > > python” using just 3 steps! But it turns out you have nothing. You
> > > are an empty promiser.
> >
> > You are being mean. It is quite evident that English is not his first
> > language, and highly probable that this was actually the question "How
> > do I automate a Java application using Python?"
> >
> > I don't have a real answer myself, but maybe using Jython one can get
> > access to the Java objects underlying the application (and then, of
> > course, execute methods of the GUI objects). This depends on the GUI
> > toolkit (Swing/SWT) and knowledge of the applications' structure, of
> > course. Another (less robust) way of desktop automation is Sikuli
> > http://www.sikuli.org/ (Windows only, I think)
> >
> >   Christian
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-16 Thread vern . muhr
On Thursday, September 15, 2016 at 11:57:04 PM UTC-7, meInvent bbird wrote:
> On Friday, September 16, 2016 at 2:26:47 AM UTC+8, [email protected] wrote:
> > On Thursday, September 15, 2016 at 8:13:05 AM UTC+1, meInvent bbird wrote:
> > > how to automate java application in window using python
> > > 
> > > 1. scroll up or down of scroll bar
> > > 2. click button
> > > 3. type text in textbox
> > 

Check out Sikuli at www.sikuli.org. It uses Jython, but hopefully that is close 
enough.

Best, Vern
-- 
https://mail.python.org/mailman/listinfo/python-list


How to get the source code of python function being decorated?

2016-09-16 Thread Peng Yu
Hi, See the following example, I am not able to get the source code of
the actual function that does the calculation of partial_ratio. Does
anybody know what is the correct way of getting the source?

/tmp$ ./main.py
@functools.wraps(func)
def decorator(*args, **kwargs):
if args[0] is None or args[1] is None:
return 0
return func(*args, **kwargs)

/tmp$ cat ./main.py
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import fuzzywuzzy.fuzz
import inspect
print inspect.getsource(fuzzywuzzy.fuzz.partial_ratio)

-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread Gary Herron

On 09/16/2016 04:24 AM, meInvent bbird wrote:

im = img.copy()
cntcounter = 0
for cnt in contours:
 epsilon = 0.1*cv2.arcLength(cnt,True)
 approx = cv2.approxPolyDP(cnt,epsilon,True)
 #peri = cv2.arcLength(cnt, True)
 #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
 #print("len(approx)="+str(len(approx)))
 if len(approx) == 4:
 print("approx=" + str(approx))
 cntcounter = cntcounter + 1
 print("here1")
 x,y,w,h = cv2.boundingRect(cnt)
 print("here2")
 while im is None:
 time.sleep(1)
 if im is not None:
 print("here3")
 im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
 #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
 #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)


cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)



These two lines:

  while im is None:
time.sleep(1)

are an infinite loop if im is None;


Since you haven't told us what im (or img, contours, cv2) are, I can't 
tell how im might become None, but it does look like you (confusingly) 
use im for two different things:  an img.copy() and a cv2.rectangle, 
whatever those may be.


Pure guesswork:  if cv2.rectangle draws a rectangle, what does it 
return?  If it doesn't return anything, the line

im = cv2.rectangle(...)
is how im gets the value of None.

--
Dr. Gary Herron
Professor of Computer Science
DigiPen Institute of Technology
(425) 895-4418

--
https://mail.python.org/mailman/listinfo/python-list


How to install Python.h on FreeBSD 10.0-RELEASE?

2016-09-16 Thread Don Kuenz

The installed python packages are shown below. Searches lead me to
believe that a PTH option make play a role.


$ uname -v
FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 
[email protected]:/usr/obj/usr/src/sys/GENERIC

$ pkg info | grep python
py27-dnspython-1.14.0  DNS toolkit for Python
py27-notify-0.1.1_11   python bindings for libnotify
py27-telepathy-python-0.15.19_1 Python bindings for the Telepathy framework
python-2.7_2,2 The "meta-port" for the default version of 
Python interpreter
python2-2_3The "meta-port" for version 2 of the Python 
interpreter
python27-2.7.12Interpreted object-oriented programming language
python3-3_3The "meta-port" for version 3 of the Python 
interpreter
python34-3.4.5 Interpreted object-oriented programming language

$ cd /usr/ports/lang/python
$ make config
===> No options to configure

---

Thank you,

--
Don Kuenz KB7RPU

There be triple ways to take, of the eagle or the snake,
Or the way of a man with a maid;
But the seetest way to me is a ship's upon the sea
In the heel of the Northeast Trade.
  - Kipling
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread Gary Herron

On 09/16/2016 05:18 AM, meInvent bbird wrote:

i follow this post to give some time it to operate,
wait a long time still looping

http://answers.opencv.org/question/60094/libpng-warning-image-width-is-zero-in-ihdr/


i can not stand this Ninja coding life any more,
i have to open my code for ask this error


import cv2
import numpy as np
#from matplotlib import pyplot as plt
import time

#print("1=" + str(int(sys.argv[1])))
#print("2=" + str(int(sys.argv[2])))
#print("3=" + str(int(sys.argv[3])))

img_rgb = cv2.imread(r'C:\Users\martin\Documents\scree2.png')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(r'C:\Users\martin\Documents\dragob.png',0)
w, h = template.shape[::-1]

res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.64
 
loc = np.where( res >= threshold)

pt = [(0,0)]
 
while not zip(*loc[::-1]):

 threshold = threshold - 0.02
 loc = np.where( res >= threshold)

counter = 1
print("threshold="+str(threshold))
for pt2 in zip(*loc[::-1]):
 cv2.rectangle(img_rgb, pt2, (pt2[0] + w, pt2[1] + h), (0,0,255), 2)
 pt = pt2
 crop_img = img_rgb[pt[1]:(pt[1]+h), pt[0]:(pt[0]+w)]
 counter = counter + 1

cv2.imwrite("C:\\Users\\tester\\Documents\\res.png",crop_img)


#import cv2
#winName = "Movement Indicator"
#cv2.namedWindow(winName, cv2.WINDOW_NORMAL)
img = cv2.imread(r'C:\Users\tester\Documents\res.png',1)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
height, width = gray.shape
edges = cv2.Canny(gray,height,width,apertureSize = 3)
#edges = cv2.Canny(gray,30,200)

#gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
#ret,thresh = 
cv2.threshold(edges.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE,0)
ret,thresh = cv2.threshold(edges,250,150,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
#contours = sorted(contours, key = cv2.contourArea, reverse = True)[:10]

im = img.copy()
cntcounter = 0
for cnt in contours:
 epsilon = 0.1*cv2.arcLength(cnt,True)
 approx = cv2.approxPolyDP(cnt,epsilon,True)
 #peri = cv2.arcLength(cnt, True)
 #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
 #print("len(approx)="+str(len(approx)))
 if len(approx) == 4:
 print("approx=" + str(approx))
 cntcounter = cntcounter + 1
 print("here1")
 x,y,w,h = cv2.boundingRect(cnt)
 print("here2")
 #im = img.copy()
 while im is None:
 time.sleep(1)
 if im is not None:
 print("here3")
 im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
 
#cv2.imwrite("C:\\Users\\martin\\Documents\\masda"+str(cntcounter)+".png",imi)
 #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
 #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)








On Friday, September 16, 2016 at 7:34:04 PM UTC+8, Waffle wrote:

On 16 September 2016 at 14:24, meInvent bbird  wrote:

im = img.copy()
cntcounter = 0
for cnt in contours:
 epsilon = 0.1*cv2.arcLength(cnt,True)
 approx = cv2.approxPolyDP(cnt,epsilon,True)
 #peri = cv2.arcLength(cnt, True)
 #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
 #print("len(approx)="+str(len(approx)))
 if len(approx) == 4:
 print("approx=" + str(approx))
 cntcounter = cntcounter + 1
 print("here1")
 x,y,w,h = cv2.boundingRect(cnt)
 print("here2")
 while im is None:
 time.sleep(1)
 if im is not None:
 print("here3")
 im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
 #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
 #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)


cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)
--
https://mail.python.org/mailman/listinfo/python-list

not sure but..  this bit reads really suspicious:

 while im is None:
 time.sleep(1)

if im is ever None then how will it ever become not None? unless there
is some other thread at work i can't really see this happening.
and if there is some other thread at work then there is probably some
better solution than sleep()


Reading the manual for opencv, we see that cv2.rectangle does indeed 
return None:
  Python: cv.Rectangle(img, pt1, pt2, color, thickness=1, 
lineType=8, shift=0) → None


So the first pass through your loop does indeed set im to None with the line
im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
and the next pass through the loop hits the infinite loop:
while im is None:
time.sleep(1)


--
Dr. Gary Herron
Pro

Re: Discover all non-standard library modules imported by a script

2016-09-16 Thread Terry Reedy

On 9/16/2016 7:29 AM, Malcolm Greene wrote:

Looking for suggestions on how, given a main script, discover all the
non-standard library modules imported across all modules, eg. the
modules that other modules import, etc. I'm not looking to discover
dynamic imports or other edge cases, just the list modules loaded via
"import " and "from  import ...". I know I could write a
script to do this, but certainly there must be such a capability in the
standard library?

Use case: Discovering list of modules to use for building a Python 3.5
zipapp distributable.


You could check the .__file__ attribute of each module in sys.modules 
for 'site-packages', (or more generally, for non-stdlib locations).


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread MRAB

On 2016-09-16 20:14, Gary Herron wrote:

On 09/16/2016 04:24 AM, meInvent bbird wrote:

im = img.copy()
cntcounter = 0
for cnt in contours:
 epsilon = 0.1*cv2.arcLength(cnt,True)
 approx = cv2.approxPolyDP(cnt,epsilon,True)
 #peri = cv2.arcLength(cnt, True)
 #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
 #print("len(approx)="+str(len(approx)))
 if len(approx) == 4:
 print("approx=" + str(approx))
 cntcounter = cntcounter + 1
 print("here1")
 x,y,w,h = cv2.boundingRect(cnt)
 print("here2")
 while im is None:
 time.sleep(1)
 if im is not None:
 print("here3")
 im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
 #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
 #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
 #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)


cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)



These two lines:

   while im is None:
 time.sleep(1)

are an infinite loop if im is None;


Since you haven't told us what im (or img, contours, cv2) are, I can't
tell how im might become None, but it does look like you (confusingly)
use im for two different things:  an img.copy() and a cv2.rectangle,
whatever those may be.

Pure guesswork:  if cv2.rectangle draws a rectangle, what does it
return?  If it doesn't return anything, the line
 im = cv2.rectangle(...)
is how im gets the value of None.


It looks like the OP is using OpenCV.

You're right about cv2.rectangle; it does return None.

The line:

im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)

makes a copy of the image im, draws a rectangle on it, and then binds 
None to im.


The copied rectangle is discarded because there's no reference to it, so 
the entire line in pointless.


It basically does the same thing as:

im = None

only slower!

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to get the source code of python function being decorated?

2016-09-16 Thread Ned Batchelder
On Friday, September 16, 2016 at 3:20:15 PM UTC-4, Peng Yu wrote:
> Hi, See the following example, I am not able to get the source code of
> the actual function that does the calculation of partial_ratio. Does
> anybody know what is the correct way of getting the source?
> 
> /tmp$ ./main.py
> @functools.wraps(func)
> def decorator(*args, **kwargs):
> if args[0] is None or args[1] is None:
> return 0
> return func(*args, **kwargs)
> 
> /tmp$ cat ./main.py
> #!/usr/bin/env python
> # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 
> fileencoding=utf-8:
> 
> import fuzzywuzzy.fuzz
> import inspect
> print inspect.getsource(fuzzywuzzy.fuzz.partial_ratio)
>

In general, you can't get at the decorated function. Decorators can
do anything they want with the function they decorate, including
completely ignore it, or store it in a closure, assign it to a global,
add it to a data structure, etc.

Can you tell us more about the problem you are trying to solve? Why
do you want a program that access the source of decorated functions?
Maybe there's another way to get at what you need.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get the source code of python function being decorated?

2016-09-16 Thread Peter Otten
Peng Yu wrote:

> Hi, See the following example, I am not able to get the source code of
> the actual function that does the calculation of partial_ratio. Does
> anybody know what is the correct way of getting the source?
> 
> /tmp$ ./main.py
> @functools.wraps(func)
> def decorator(*args, **kwargs):
> if args[0] is None or args[1] is None:
> return 0
> return func(*args, **kwargs)
> 
> /tmp$ cat ./main.py
> #!/usr/bin/env python
> # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1
> # fileencoding=utf-8:
> 
> import fuzzywuzzy.fuzz
> import inspect
> print inspect.getsource(fuzzywuzzy.fuzz.partial_ratio)

In Python 3 functools.wraps() records the wrapped function as __wrapped__:

$ cat tmp.py
import functools

def spam(func):
@functools.wraps(func)
def decorator(*args, **kwargs):
return func(*args, **kwargs)
return decorator

@spam
def ham(foo, bar):
return 42

$ python3
...
>>> import inspect
>>> import tmp  
>>> print(inspect.getsource(tmp.ham))
@functools.wraps(func)
def decorator(*args, **kwargs):
return func(*args, **kwargs)

>>> print(inspect.getsource(tmp.ham.__wrapped__))
@spam
def ham(foo, bar):
return 42

In Python 2 when you look into the attributes of tmp.ham() using dir() 
you'll eventually find

>>> print inspect.getsource(tmp.ham.__closure__[0].cell_contents)
@spam
def ham(foo, bar):
return 42

but I'm not sure this is general enough to spare you the look into the 
source code.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Discover all non-standard library modules imported by a script

2016-09-16 Thread Malcolm Greene
Thanks for your suggestions Chris and Terry.

The answer I was looking for is the modulefinder module which is part of
the standard lib. Works like a charm!

Quote: This module provides a ModuleFinder class that can be used to
determine the set of modules imported by a script. modulefinder.py can
also be run as a script, giving the filename of a Python script as its
argument, after which a report of the imported modules will be printed.

https://docs.python.org/3.5/library/modulefinder.html 

Note there's a similar module for Python 2.7.

--
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Looking for tips and gotchas for working with Python 3.5 zipapp feature

2016-09-16 Thread Malcolm Greene
Looking for tips or edge case gotchas associated with using Python 3.5's
new zipapp feature. For those of you wondering what this feature is, see
the end of this post for a brief background [1].

Two questions in particular:

1. Are there any issues with deploying scripts that sit in sub-
   folders beneath the directory being zipped, eg. does zipapp only
   support a flat folder of scripts or does it recursively zip and
   path sub-folders?

2. Can additional non-Python files like config files be added to a
   zipapp without breaking them and if so, how would your script
   reference these embedded files (by opening up the zipapp as a zip
   archive and navigating from there?).

Thank you,
Malcolm

[1] The zipapp feature of Python 3.5 is pretty cool: It allows you to
package your Python scripts in a single executable zip file. This
isn't a replacement for tools like PyInstaller or Py2Exe, eg. it
doesn't bundle the Python interpreter in the zip file, but it's a
clean way to distribute multi-file scripts in environments where you
have control over users' Python setups.

Here's the manual page:

zipapp — Manage executable python zip archives
https://docs.python.org/3/library/zipapp.html

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread meInvent bbird
thank you very much,
it out of the loop now.
because drawLine function return things

i just change drawLine to rectangle,
have not thought that rectangle not return thing, just edit the parameter



On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote:
> On 2016-09-16 20:14, Gary Herron wrote:
> > On 09/16/2016 04:24 AM, meInvent bbird wrote:
> >> im = img.copy()
> >> cntcounter = 0
> >> for cnt in contours:
> >>  epsilon = 0.1*cv2.arcLength(cnt,True)
> >>  approx = cv2.approxPolyDP(cnt,epsilon,True)   
> >>  #peri = cv2.arcLength(cnt, True)
> >>  #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
> >>  #print("len(approx)="+str(len(approx)))
> >>  if len(approx) == 4:
> >>  print("approx=" + str(approx))
> >>  cntcounter = cntcounter + 1
> >>  print("here1")
> >>  x,y,w,h = cv2.boundingRect(cnt)
> >>  print("here2")
> >>  while im is None:
> >>  time.sleep(1)
> >>  if im is not None:
> >>  print("here3")
> >>  im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), 
> >> (0,255,0), 2)
> >>  #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
> >>  #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
> >>  #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
> >>  #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)
> >>
> >>
> >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)
> >
> >
> > These two lines:
> >
> >while im is None:
> >  time.sleep(1)
> >
> > are an infinite loop if im is None;
> >
> >
> > Since you haven't told us what im (or img, contours, cv2) are, I can't
> > tell how im might become None, but it does look like you (confusingly)
> > use im for two different things:  an img.copy() and a cv2.rectangle,
> > whatever those may be.
> >
> > Pure guesswork:  if cv2.rectangle draws a rectangle, what does it
> > return?  If it doesn't return anything, the line
> >  im = cv2.rectangle(...)
> > is how im gets the value of None.
> >
> It looks like the OP is using OpenCV.
> 
> You're right about cv2.rectangle; it does return None.
> 
> The line:
> 
>  im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
> 
> makes a copy of the image im, draws a rectangle on it, and then binds 
> None to im.
> 
> The copied rectangle is discarded because there's no reference to it, so 
> the entire line in pointless.
> 
> It basically does the same thing as:
> 
>  im = None
> 
> only slower!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread meInvent bbird
img is the image

im is a new memory of image using  img.copy()


On Saturday, September 17, 2016 at 7:46:42 AM UTC+8, meInvent bbird wrote:
> thank you very much,
> it out of the loop now.
> because drawLine function return things
> 
> i just change drawLine to rectangle,
> have not thought that rectangle not return thing, just edit the parameter
> 
> 
> 
> On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote:
> > On 2016-09-16 20:14, Gary Herron wrote:
> > > On 09/16/2016 04:24 AM, meInvent bbird wrote:
> > >> im = img.copy()
> > >> cntcounter = 0
> > >> for cnt in contours:
> > >>  epsilon = 0.1*cv2.arcLength(cnt,True)
> > >>  approx = cv2.approxPolyDP(cnt,epsilon,True) 
> > >>  #peri = cv2.arcLength(cnt, True)
> > >>  #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
> > >>  #print("len(approx)="+str(len(approx)))
> > >>  if len(approx) == 4:
> > >>  print("approx=" + str(approx))
> > >>  cntcounter = cntcounter + 1
> > >>  print("here1")
> > >>  x,y,w,h = cv2.boundingRect(cnt)
> > >>  print("here2")
> > >>  while im is None:
> > >>  time.sleep(1)
> > >>  if im is not None:
> > >>  print("here3")
> > >>  im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), 
> > >> (0,255,0), 2)
> > >>  #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
> > >>  #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
> > >>  #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
> > >>  #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)
> > >>
> > >>
> > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)
> > >
> > >
> > > These two lines:
> > >
> > >while im is None:
> > >  time.sleep(1)
> > >
> > > are an infinite loop if im is None;
> > >
> > >
> > > Since you haven't told us what im (or img, contours, cv2) are, I can't
> > > tell how im might become None, but it does look like you (confusingly)
> > > use im for two different things:  an img.copy() and a cv2.rectangle,
> > > whatever those may be.
> > >
> > > Pure guesswork:  if cv2.rectangle draws a rectangle, what does it
> > > return?  If it doesn't return anything, the line
> > >  im = cv2.rectangle(...)
> > > is how im gets the value of None.
> > >
> > It looks like the OP is using OpenCV.
> > 
> > You're right about cv2.rectangle; it does return None.
> > 
> > The line:
> > 
> >  im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
> > 
> > makes a copy of the image im, draws a rectangle on it, and then binds 
> > None to im.
> > 
> > The copied rectangle is discarded because there's no reference to it, so 
> > the entire line in pointless.
> > 
> > It basically does the same thing as:
> > 
> >  im = None
> > 
> > only slower!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code loop forever after a draw a rectangle

2016-09-16 Thread meInvent bbird
after succeed to draw lines in graph,

however,

https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing

expected the blue line connect the bottom of red line graph

https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing

how can convex hull be adjusted to do like second graph of sky blue line


On Saturday, September 17, 2016 at 7:48:46 AM UTC+8, meInvent bbird wrote:
> img is the image
> 
> im is a new memory of image using  img.copy()
> 
> 
> On Saturday, September 17, 2016 at 7:46:42 AM UTC+8, meInvent bbird wrote:
> > thank you very much,
> > it out of the loop now.
> > because drawLine function return things
> > 
> > i just change drawLine to rectangle,
> > have not thought that rectangle not return thing, just edit the parameter
> > 
> > 
> > 
> > On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote:
> > > On 2016-09-16 20:14, Gary Herron wrote:
> > > > On 09/16/2016 04:24 AM, meInvent bbird wrote:
> > > >> im = img.copy()
> > > >> cntcounter = 0
> > > >> for cnt in contours:
> > > >>  epsilon = 0.1*cv2.arcLength(cnt,True)
> > > >>  approx = cv2.approxPolyDP(cnt,epsilon,True)   
> > > >>  #peri = cv2.arcLength(cnt, True)
> > > >>  #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
> > > >>  #print("len(approx)="+str(len(approx)))
> > > >>  if len(approx) == 4:
> > > >>  print("approx=" + str(approx))
> > > >>  cntcounter = cntcounter + 1
> > > >>  print("here1")
> > > >>  x,y,w,h = cv2.boundingRect(cnt)
> > > >>  print("here2")
> > > >>  while im is None:
> > > >>  time.sleep(1)
> > > >>  if im is not None:
> > > >>  print("here3")
> > > >>  im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), 
> > > >> (0,255,0), 2)
> > > >>  #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
> > > >>  #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
> > > >>  #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
> > > >>  #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)
> > > >>
> > > >>
> > > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)
> > > >
> > > >
> > > > These two lines:
> > > >
> > > >while im is None:
> > > >  time.sleep(1)
> > > >
> > > > are an infinite loop if im is None;
> > > >
> > > >
> > > > Since you haven't told us what im (or img, contours, cv2) are, I can't
> > > > tell how im might become None, but it does look like you (confusingly)
> > > > use im for two different things:  an img.copy() and a cv2.rectangle,
> > > > whatever those may be.
> > > >
> > > > Pure guesswork:  if cv2.rectangle draws a rectangle, what does it
> > > > return?  If it doesn't return anything, the line
> > > >  im = cv2.rectangle(...)
> > > > is how im gets the value of None.
> > > >
> > > It looks like the OP is using OpenCV.
> > > 
> > > You're right about cv2.rectangle; it does return None.
> > > 
> > > The line:
> > > 
> > >  im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)
> > > 
> > > makes a copy of the image im, draws a rectangle on it, and then binds 
> > > None to im.
> > > 
> > > The copied rectangle is discarded because there's no reference to it, so 
> > > the entire line in pointless.
> > > 
> > > It basically does the same thing as:
> > > 
> > >  im = None
> > > 
> > > only slower!

-- 
https://mail.python.org/mailman/listinfo/python-list


is it possible to adjust convex hull to draw blue line instead of green line?

2016-09-16 Thread meInvent bbird
i succeed to use code to draw green line, but green line not draw the 
large area, expect second uploaded picture, the blue line connect
the bottom of red line graph

im = img.copy()
cntcounter = 0
for cnt in contours:
#epsilon = 0.1*cv2.arcLength(cnt,True)
#approx = cv2.approxPolyDP(cnt,epsilon,True)
#peri = cv2.arcLength(cnt, True)
#approx = cv2.approxPolyDP(cnt, 0.15 * peri, True)
#print("len(approx)="+str(len(approx)))
#if len(approx) == 2:
print("approx=" + str(approx))
cntcounter = cntcounter + 1
print("here1")
#x,y,w,h = cv2.boundingRect(cnt)
hull = cv2.convexHull(cnt,returnPoints = True)
print("here2")
while im is None:
time.sleep(1)
if im is not None:
print("here3")
#cv2.rectangle(im, (x,y), (x+w, y+h), (0,255,0), 2) 

#cv2.imwrite("C:\\Users\\tester\\Documents\\masda"+str(cntcounter)+".png",imi)  
  
#im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
#im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
#im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
#im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)
previousx = 0
previousy = 0 
for c in hull: 
if previousx != 0 and previousy != 0 and c[0][0] != 0 and 
c[0][1] != 0 and abs(previousy - c[0][1]) > 10 and abs(c[0][0] - previousx) > 
1:
while im is None:
time.sleep(1)

cv2.line(im,(previousx,previousy),(c[0][0],c[0][1]),(0,255,0),2)
print("")
#print("previousx=" + str(previousx))
#print("previousy=" + str(previousy))
#print("c[0][0]=" + str(c[0][0]))
#print("c[0][1]=" + str(c[0][1]))
previousx = c[0][0]
previousy = c[0][1]



https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing

expected is

https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is it possible to adjust convex hull to draw blue line instead of green line?

2016-09-16 Thread Steve D'Aprano
On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote:

> i succeed to use code to draw green line, but green line not draw the
> large area, expect second uploaded picture, the blue line connect
> the bottom of red line graph


Please don't waste our time with dead code that has been commented out or
that doesn't do anything.

Here is your code with the commented out dead code removed. You should do
this, don't expect us to do it:


im = img.copy()
cntcounter = 0
for cnt in contours:
print("approx=" + str(approx))
cntcounter = cntcounter + 1
print("here1")
hull = cv2.convexHull(cnt,returnPoints = True)
print("here2")
while im is None:
# WARNING: THIS IS AN INFINITE LOOP
time.sleep(1)
if im is not None:
print("here3")
previousx = 0
previousy = 0 
for c in hull: 
if (previousx != 0 and previousy != 0 and c[0][0] != 0
and c[0][1] != 0 and abs(previousy - c[0][1]) > 10
and abs(c[0][0] - previousx) > 1
):
while im is None:
# WARNING: THIS IS AN INFINITE LOOP
time.sleep(1)
cv2.line(im, (previousx, previousy),
 (c[0][0], c[0][1]), (0, 255, 0), 2)
print("")
previousx = c[0][0]
previousy = c[0][1]




Now it is much easier to read without the noise.

Problems:

(1) img is not defined;

(2) approx is not defined;

(3) contours is not defined;

(4) cv2 is not defined;

(5) you have TWO possible infinite loops in your code;

(6) time is not defined, but this at least I can guess is the 
standard time module;

(7) c is not defined.


As given to us, we cannot run your code or understand it, because too many
things are undefined.

My **guess** is that cv2.line() will take an argument to set the line
colour. You should read the documentation for cv2.line().


Before asking any more questions, please read this:

http://sscce.org/






-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to automate java application in window using python

2016-09-16 Thread Lawrence D’Oliveiro
On Friday, September 16, 2016 at 10:22:34 PM UTC+12, Christian Gollwitzer wrote:
> "How do I automate a Java application using Python?"

Which is really a meaningless question. “Automation” is what computer programs 
do. (Assuming “application” is just another word for “program”.) If the program 
doesn’t work the way you expect, fix it.

But then, “automation” and “GUI” never really went together, did they 
 ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is it possible to adjust convex hull to draw blue line instead of green line?

2016-09-16 Thread MRAB

On 2016-09-17 01:20, meInvent bbird wrote:

i succeed to use code to draw green line, but green line not draw the
large area, expect second uploaded picture, the blue line connect
the bottom of red line graph


[snip]

Here's the code with the commented code and print statements removed and 
the indentation fixed:



im = img.copy()

for cnt in contours:
hull = cv2.convexHull(cnt, returnPoints=True)
previousx = 0
previousy = 0

for c in hull:
if previousx != 0 and previousy != 0 and c[0][0] != 0 and 
c[0][1] != 0 and abs(previousy - c[0][1]) > 10 and abs(c[0][0] - 
previousx) > 1:
cv2.line(im, (previousx, previousy), (c[0][0], c[0][1]), 
(0, 255, 0), 2)


previousx = c[0][0]
previousy = c[0][1]



https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing

expected is

https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing

I think the problem might be that you're setting previousx to c[0][0] 
and previousy to c[0][1] even if you don't draw the line (because of the 
indentation), so you get a series of unconnected lines.


I'm not sure whether you should be setting previousx and previousy to 0 
each time around the outer loop. I can't test it, but if the previous 
fix doesn't work, it's one more thing to try.

--
https://mail.python.org/mailman/listinfo/python-list


Where is the documentation for ','?

2016-09-16 Thread Peng Yu
Hi,

I'm wondering where is the documentation for ',' as in the following usage.

x = 1
y = 2
x, y = y, x

I tried help(','). But there are too many ',' in it and I don't see in
which section ',' is documented. Could anybody let me know? Thanks.

-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread MRAB

On 2016-09-17 03:05, Peng Yu wrote:

Hi,

I'm wondering where is the documentation for ',' as in the following usage.

x = 1
y = 2
x, y = y, x

I tried help(','). But there are too many ',' in it and I don't see in
which section ',' is documented. Could anybody let me know? Thanks.


Search for 'tuple' instead.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread Peng Yu
help(tuple) gives me this, which does not mention ',' either.

Help on class tuple in module __builtin__:

class tuple(object)
 |  tuple() -> empty tuple
 |  tuple(iterable) -> tuple initialized from iterable's items
 |
 |  If the argument is a tuple, the return value is the same object.
 |
 |  Methods defined here:
 |
 |  __add__(...)
 |  x.__add__(y) <==> x+y
 |
 |  __contains__(...)
 |  x.__contains__(y) <==> y in x
 |
 |  __eq__(...)
 |  x.__eq__(y) <==> x==y
 |
 |  __ge__(...)
 |  x.__ge__(y) <==> x>=y
 |
 |  __getattribute__(...)
 |  x.__getattribute__('name') <==> x.name
 |
 |  __getitem__(...)
 |  x.__getitem__(y) <==> x[y]
 |
 |  __getnewargs__(...)
 |
 |  __getslice__(...)
 |  x.__getslice__(i, j) <==> x[i:j]
 |
 |  Use of negative indices is not supported.
 |
 |  __gt__(...)
 |  x.__gt__(y) <==> x>y
 |
 |  __hash__(...)
 |  x.__hash__() <==> hash(x)
 |
 |  __iter__(...)
 |  x.__iter__() <==> iter(x)
 |
 |  __le__(...)
 |  x.__le__(y) <==> x<=y
 |
 |  __len__(...)
 |  x.__len__() <==> len(x)
 |
 |  __lt__(...)
 |  x.__lt__(y) <==> x x*n
 |
 |  __ne__(...)
 |  x.__ne__(y) <==> x!=y
 |
 |  __repr__(...)
 |  x.__repr__() <==> repr(x)
 |
 |  __rmul__(...)
 |  x.__rmul__(n) <==> n*x
 |
 |  count(...)
 |  T.count(value) -> integer -- return number of occurrences of value
 |
 |  index(...)
 |  T.index(value, [start, [stop]]) -> integer -- return first
index of value.
 |  Raises ValueError if the value is not present.
 |
 |  --
 |  Data and other attributes defined here:
 |
 |  __new__ = 
 |  T.__new__(S, ...) -> a new object with type S, a subtype of T



On Fri, Sep 16, 2016 at 9:13 PM, MRAB  wrote:
> On 2016-09-17 03:05, Peng Yu wrote:
>>
>> Hi,
>>
>> I'm wondering where is the documentation for ',' as in the following
>> usage.
>>
>> x = 1
>> y = 2
>> x, y = y, x
>>
>> I tried help(','). But there are too many ',' in it and I don't see in
>> which section ',' is documented. Could anybody let me know? Thanks.
>>
> Search for 'tuple' instead.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Is there something similar to `set -v` of bash in python

2016-09-16 Thread Peng Yu
Hi, `set -v` in bash allows the print of the command before print the
output of the command.

I want to do the similar thing --- print a python command and then
print the output of the command. Is it possible with python?

-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread Lawrence D’Oliveiro
On Saturday, September 17, 2016 at 2:05:49 PM UTC+12, Peng Yu wrote:
> x, y = y, x

It’s just syntactic sugar for

(x, y) = (y, x)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread Peng Yu
OK. But it is documented somewhere in python doc?

On Fri, Sep 16, 2016 at 9:48 PM, Lawrence D’Oliveiro
 wrote:
> On Saturday, September 17, 2016 at 2:05:49 PM UTC+12, Peng Yu wrote:
>> x, y = y, x
>
> It’s just syntactic sugar for
>
> (x, y) = (y, x)
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,
Peng
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread Nathan Ernst
The grammar and what it represents is defined at
https://docs.python.org/3/reference/expressions.html#expression-lists

Regards

On Sep 16, 2016 9:59 PM, "Peng Yu"  wrote:

> OK. But it is documented somewhere in python doc?
>
> On Fri, Sep 16, 2016 at 9:48 PM, Lawrence D’Oliveiro
>  wrote:
> > On Saturday, September 17, 2016 at 2:05:49 PM UTC+12, Peng Yu wrote:
> >> x, y = y, x
> >
> > It’s just syntactic sugar for
> >
> > (x, y) = (y, x)
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> Regards,
> Peng
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread Ben Finney
Peng Yu  writes:

> help(tuple) gives me this

Yes. That's the API definition for the ‘tuple’ type.

You were advised to search the documentation, not the interactive
help. You'll find the descriptions of “tuple” and even “tuple unpacking”
are what you want.

-- 
 \ “When I turned two I was really anxious, because I'd doubled my |
  `\   age in a year. I thought, if this keeps up, by the time I'm six |
_o__)  I'll be ninety.” —Steven Wright |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


array.itemsize: Documentation Versus Reality

2016-09-16 Thread Lawrence D’Oliveiro
>>> a = array.array("I", (0,))
>>> a.itemsize
4
>>> a = array.array("L", (0,))
>>> a.itemsize
8

According to , the “minimum size” 
should be 2 and 4 respectively. It further says:

The actual representation of values is determined by the machine
architecture (strictly speaking, by the C implementation).
The actual size can be accessed through the itemsize attribute.

Are there any C compilers still in common use where the values will not be 4 
and 8, as above?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread Terry Reedy

On 9/16/2016 10:05 PM, Peng Yu wrote:

Hi,

I'm wondering where is the documentation for ',' as in the following usage.

x = 1
y = 2
x, y = y, x

I tried help(','). But there are too many ',' in it and I don't see in
which section ',' is documented. Could anybody let me know? Thanks.


It should be indexed on
https://docs.python.org/3/genindex-Symbols.html
but is not.  I will try to remember to fix it.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread eryk sun
On Sat, Sep 17, 2016 at 2:05 AM, Peng Yu  wrote:
>
> I'm wondering where is the documentation for ',' as in the following usage.
>
> x = 1
> y = 2
> x, y = y, x
>
> I tried help(','). But there are too many ',' in it and I don't see in
> which section ',' is documented. Could anybody let me know? Thanks.

See help('ASSIGNMENT') where the "target list is a comma-separated
list of targets". See also help('TUPLELITERALS') and
help('SEQUENCES').
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is it possible to adjust convex hull to draw blue line instead of green line?

2016-09-16 Thread meInvent bbird
On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote:
> On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote:
> 
> > i succeed to use code to draw green line, but green line not draw the
> > large area, expect second uploaded picture, the blue line connect
> > the bottom of red line graph
> 
> 
> Please don't waste our time with dead code that has been commented out or
> that doesn't do anything.
> 
> Here is your code with the commented out dead code removed. You should do
> this, don't expect us to do it:
> 
> 
> im = img.copy()
> cntcounter = 0
> for cnt in contours:
> print("approx=" + str(approx))
> cntcounter = cntcounter + 1
> print("here1")
> hull = cv2.convexHull(cnt,returnPoints = True)
> print("here2")
> while im is None:
> # WARNING: THIS IS AN INFINITE LOOP
> time.sleep(1)
> if im is not None:
> print("here3")
> previousx = 0
> previousy = 0 
> for c in hull: 
> if (previousx != 0 and previousy != 0 and c[0][0] != 0
> and c[0][1] != 0 and abs(previousy - c[0][1]) > 10
> and abs(c[0][0] - previousx) > 1
> ):
> while im is None:
> # WARNING: THIS IS AN INFINITE LOOP
> time.sleep(1)
> cv2.line(im, (previousx, previousy),
>  (c[0][0], c[0][1]), (0, 255, 0), 2)
> print("")
> previousx = c[0][0]
> previousy = c[0][1]
> 
> 
> 
> 
> Now it is much easier to read without the noise.
> 
> Problems:
> 
> (1) img is not defined;
> 
> (2) approx is not defined;
> 
> (3) contours is not defined;
> 
> (4) cv2 is not defined;
> 
> (5) you have TWO possible infinite loops in your code;
> 
> (6) time is not defined, but this at least I can guess is the 
> standard time module;
> 
> (7) c is not defined.
> 
> 
> As given to us, we cannot run your code or understand it, because too many
> things are undefined.
> 
> My **guess** is that cv2.line() will take an argument to set the line
> colour. You should read the documentation for cv2.line().
> 
> 
> Before asking any more questions, please read this:
> 
> http://sscce.org/
> 
> 
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

sorry for assuming all have experience in this kind of application

here is my code

https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60

Please.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is the documentation for ','?

2016-09-16 Thread Steve D'Aprano
On Sat, 17 Sep 2016 12:05 pm, Peng Yu wrote:

> Hi,
> 
> I'm wondering where is the documentation for ',' as in the following
> usage.
> 
> x = 1
> y = 2
> x, y = y, x
> 
> I tried help(','). But there are too many ',' in it and I don't see in
> which section ',' is documented. Could anybody let me know? Thanks.


As well as the other suggestions you have been given, try "Sequence
Unpacking".



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there something similar to `set -v` of bash in python

2016-09-16 Thread Steve D'Aprano
On Sat, 17 Sep 2016 12:31 pm, Peng Yu wrote:

> Hi, `set -v` in bash allows the print of the command before print the
> output of the command.
> 
> I want to do the similar thing --- print a python command and then
> print the output of the command. Is it possible with python?


There is no built-in command for this, but it would be an interesting
project for an advanced user to write a pre-processor that inserts calls to
print after every line.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is it possible to adjust convex hull to draw blue line instead of green line?

2016-09-16 Thread meInvent bbird
On Saturday, September 17, 2016 at 2:31:59 PM UTC+8, meInvent bbird wrote:
> On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote:
> > On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote:
> > 
> > > i succeed to use code to draw green line, but green line not draw the
> > > large area, expect second uploaded picture, the blue line connect
> > > the bottom of red line graph
> > 
> > 
> > Please don't waste our time with dead code that has been commented out or
> > that doesn't do anything.
> > 
> > Here is your code with the commented out dead code removed. You should do
> > this, don't expect us to do it:
> > 
> > 
> > im = img.copy()
> > cntcounter = 0
> > for cnt in contours:
> > print("approx=" + str(approx))
> > cntcounter = cntcounter + 1
> > print("here1")
> > hull = cv2.convexHull(cnt,returnPoints = True)
> > print("here2")
> > while im is None:
> > # WARNING: THIS IS AN INFINITE LOOP
> > time.sleep(1)
> > if im is not None:
> > print("here3")
> > previousx = 0
> > previousy = 0 
> > for c in hull: 
> > if (previousx != 0 and previousy != 0 and c[0][0] != 0
> > and c[0][1] != 0 and abs(previousy - c[0][1]) > 10
> > and abs(c[0][0] - previousx) > 1
> > ):
> > while im is None:
> > # WARNING: THIS IS AN INFINITE LOOP
> > time.sleep(1)
> > cv2.line(im, (previousx, previousy),
> >  (c[0][0], c[0][1]), (0, 255, 0), 2)
> > print("")
> > previousx = c[0][0]
> > previousy = c[0][1]
> > 
> > 
> > 
> > 
> > Now it is much easier to read without the noise.
> > 
> > Problems:
> > 
> > (1) img is not defined;
> > 
> > (2) approx is not defined;
> > 
> > (3) contours is not defined;
> > 
> > (4) cv2 is not defined;
> > 
> > (5) you have TWO possible infinite loops in your code;
> > 
> > (6) time is not defined, but this at least I can guess is the 
> > standard time module;
> > 
> > (7) c is not defined.
> > 
> > 
> > As given to us, we cannot run your code or understand it, because too many
> > things are undefined.
> > 
> > My **guess** is that cv2.line() will take an argument to set the line
> > colour. You should read the documentation for cv2.line().
> > 
> > 
> > Before asking any more questions, please read this:
> > 
> > http://sscce.org/
> > 
> > 
> > 
> > 
> > 
> > 
> > -- 
> > Steve
> > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> > enough, things got worse.
> 
> sorry for assuming all have experience in this kind of application
> 
> here is my code
> 
> https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60
> 
> Please.


this time, i try to run more times for contour and convex hull

but not blue line expected diagram,

is it possible to adjust the method to draw lines for the bottom of red line

https://gist.github.com/hoyeunglee/9c97fdef1cc32fefde0a454a24a2c2c1
-- 
https://mail.python.org/mailman/listinfo/python-list