Re: [Tutor] Error :SyntaxError: 'break' outside loop

2013-08-19 Thread Steven D'Aprano
Hello Zoya, and welcome!


On Sun, Aug 18, 2013 at 10:18:06AM -0700, Zoya Tavakkoli wrote:
> Hi everyone
> 
> I write this code for color segmentation ,but after Run I recived this
> error:
> 
> SyntaxError: 'break' outside loop
> 
> I could not resolve that ,could you please help me?

Is the error message not clear enough? You have a 'break' command 
outside of a loop. If the error message is not clear enough, please 
suggest something that would be more clear. Also, you should read the 
entire traceback, which will show you not just the error, but the exact 
line causing the problem.

For example, these two are legal:

# Legal
while x > 100:
if y == 0:
break
...


# Also legal
for i in range(1000):
if x > 20:
break
...


But not this:

# Not legal
if x > 20:
break


You can't break out of a loop, if you aren't inside a loop to begin 
with.


> while (1):
>  _, frame = cap.read()

You have a while loop with only one line. It loops forever, and never 
exits. Are you sure that's what you want?

By the way, it is much, much, much easier to see indentation when you 
make it four spaces or eight. Good programmer's editors let you set 
indentation to four or eight spaces. Even Notepad, which is *not* a 
programmer's editor, lets you hit the Tab key and indent. 


> hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

Because this line is not indented, it is not inside the loop.


> if k == 27:
> 
>  break

Again, because the "if" line is not indented, it is outside the loop, 
and so the break is illegal.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error :SyntaxError: 'break' outside loop

2013-08-19 Thread Chris Down
On 2013-08-19 10:55, Chris Down wrote:
> On 2013-08-18 10:18, Zoya Tavakkoli wrote:
> > if k == 27:
> >
> >  break
>
> Well, you're not in a function here, so break doesn't make any sense. What is
> it that you want to do?

s/function/loop/


pgpV6iNWSeUjo.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error :SyntaxError: 'break' outside loop

2013-08-19 Thread Chris Down
On 2013-08-18 10:18, Zoya Tavakkoli wrote:
> if k == 27:
>
>  break

Well, you're not in a function here, so break doesn't make any sense. What is
it that you want to do?


pgpYkuuMtY52T.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Error :SyntaxError: 'break' outside loop

2013-08-19 Thread Zoya Tavakkoli
Hi everyone

I write this code for color segmentation ,but after Run I recived this
error:

SyntaxError: 'break' outside loop

I could not resolve that ,could you please help me?

python.2.7.5

import cv2
import numpy as np

cap = cv2.VideoCapture("C:\Users\Zohreh\Desktop\Abdomen.MST")

while (1):
 _, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])

mask = cv2.inRange(hsv, lower_blue, upper_blue)
res = cv2.bitwise_and(frame,frame, mask= mask)

cv2.imshow("frame",frame)
cv2.imshow("mask",mask)
cv2.imshow("res",res)


k = cv2.waitkey(5) & 0xFF
if k == 27:

 break


cv2.destroyWindow()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor