我尝试了运行这个,我只使用了空格而不是标签
import time
import sys
import numpy as np
import SimpleCV
import webiopi
from ayarlar import *
GPIO = webiopi.GPIO
GPIO.setFunction(4, GPIO.OUT)
GPIO.setFunction(17, GPIO.OUT)
GPIO.setFunction(18, GPIO.OUT)
GPIO.setFunction(27, GPIO.OUT)
GPIO.setFunction(10, GPIO.OUT)
GPIO.setFunction(25, GPIO.OUT)
def dist_from_color(img_color):
matrix = (img.getNumpy()[:,:,[2,1,0]] - color) ** 2
width, height = img.size()
return matirx.sum() ** 0.5 / (width * height)
def forward():
GPIO.digitalWrite(18, GPIO.HIGH)
GPIO.digitalWrite(10, GPIO.LOW)
def reverse():
GPIO.digitalWrite(18, GPIO.LOW)
GPIO.digitalWrite(10, GPIO.HIGH)
def right():
GPIO.digitalWrite(27, GPIO.HIGH)
GPIO.digitalWrite(25, GPIO.LOW)
def left():
GPIO.digitalWrite(27, GPIO.LOW)
GPIO.digitalWrite(25, GPIO.HIGH)
def strop():
GPIO.digitalWrite(18, GPIO.LOW)
GPIO.digitalWrite(10, GPIO.LOW)
GPIO.digitalWrite(27, GPIO.LOW)
GPIO.digitalWrite(25, GPIO.LOW)
@webiopi.macro
def ButtonForward():
forward()
@webiopi.macro
def ButtonReverse():
reverse()
@webiopi.macro
def ButtonTrunLeft():
left()
@webiopi.macro
def ButtonTrunRight():
right()
@webiopi.macro
def ButtonStop():
stop()
def main():
try:
print(__doc__)
GPIO.digitalWrite(4, GPIO.HIGH)
GPIO.digitalWrite(17, GPIO.HIGH)
server = webiopi.Server(port=80)
server.addMacro(ButtonForward)
server.addMacro(ButtonReverse)
server.addMacro(ButtonTrunLeft)
server.addMacro(ButtonTrunRight)
server.addMacro(ButtonStop)
cam = SimpleCV.Camera()
background = cam.getImage()
print("Tespite Baslaniyor")
while True:
try:
background = cam.getImage()
time.sleep(0.1)
img = cam.getImage()
to_show = img
to_show.save("../../..//usr/share/webiopi/htdocs/aaa.jpg")
dist = ((img - background) + (background - img)).dilate(6)
except(KeyboardInterrupt, SystemExit):
del cam
server.stop()
即使我没有第86行,它也给了我这个恐怖
文件“tespit.py”,第86行^ IndentationError:意外的unindent 请帮帮我,我无法解决问题...
答案 0 :(得分:4)
您有两个try
语句,只有一个except
语句。
在except
函数的末尾为第一个try
添加main
子句,缩进4个空格,它将起作用。
第86行刚刚结束你的代码,并且是Python寻找匹配except
的地方。
答案 1 :(得分:0)
每个try
必须至少有一个匹配except
。
你应该在停止Webiopi服务器之前清理GPIO。