Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Don';无法理解此语法错误:注释的目标非法_Python_Python 3.x_If Statement_Syntax Error_Conditional - Fatal编程技术网

Python Don';无法理解此语法错误:注释的目标非法

Python Don';无法理解此语法错误:注释的目标非法,python,python-3.x,if-statement,syntax-error,conditional,Python,Python 3.x,If Statement,Syntax Error,Conditional,我有一些简单的假设。。。埃利夫。。。在我的python3.6(&opencv4.0)中,但无论我做什么,我总是收到奇怪的错误消息 我需要根据一些边框裁剪一些图片 # the image to be cropped loads here: tobecropped= cv2.imread(img) images.append(tobecropped) (imageheight, imagewidth) = tobecropped.shape[:2] # sample bounding box: y

我有一些简单的假设。。。埃利夫。。。在我的python3.6(&opencv4.0)中,但无论我做什么,我总是收到奇怪的错误消息

我需要根据一些边框裁剪一些图片

# the image to be cropped loads here:
tobecropped= cv2.imread(img)
images.append(tobecropped)
(imageheight, imagewidth) = tobecropped.shape[:2]

# sample bounding box:
y = 833 # center vertically
x = 183 # center horizontally
width = 172
height = 103

# calculation of cropping values adding 10% extra:
y1 = y-(height/2*1.1)
y2 = y+(height/2*1.1)
x1 = x-(width/2*1.1)
x2 = x+(width/2*1.1)

# return values to int:
y1 = int(y1)
y2 = int(y2)
x1 = int(x1)
x2 = int(x2)

# move the cropping inside the original image:
If (y1 < 0): y_movedown()
Elif (y2 > imageheight): y_moveup()
Elif (x1 < 0) : x_moveright()
Elif (x2 > imagewidth): x_moveleft()

# actually cropping the image:
cropped = tobecropped[y1:y2, x1:x2]
cv2.imshow("cropped", cropped)

# functions to move the complete bounding box inside the image boundaries:
def y_movedown():
    y2=y2-y1
    y1=0
    print("moved down!")

def y_moveup():
    y1=y1-(y2-imageheight)
    y2=imageheight
    print("moved up!")

def x_moveright():
    x2=x2-x1
    x1=0
    print("moved right!")

def x_moveleft():
    x1=x1-(x2-imagewidth)
    x2=imagewidth
    print("moved left!")
#要剪切的图像加载到此处:
tobecropped=cv2.imread(img)
images.append(tobecropped)
(imageheight,imagewidth)=待复制形状[:2]
#示例边界框:
y=833#垂直居中
x=183#水平居中
宽度=172
高度=103
#额外增加10%的裁剪值计算:
y1=y-(高度/2*1.1)
y2=y+(高度/2*1.1)
x1=x-(宽度/2*1.1)
x2=x+(宽度/2*1.1)
#将值返回到int:
y1=整数(y1)
y2=int(y2)
x1=int(x1)
x2=int(x2)
#将裁剪移动到原始图像中:
如果(y1<0):y_向下移动()
Elif(y2>imageheight):y_moveup()
Elif(x1<0):x_moveright()
Elif(x2>imagewidth):x_moveleft()
#实际裁剪图像:
被裁剪=被裁剪[y1:y2,x1:x2]
cv2.imshow(“裁剪”,裁剪)
#用于在图像边界内移动完整边界框的函数:
def y_movedown():
y2=y2-y1
y1=0
打印(“向下移动!”)
def y_moveup():
y1=y1-(y2图像高度)
y2=图像高度
打印(“上移!”)
def x_moveright():
x2=x2-x1
x1=0
打印(“向右移动!”)
def x_moveleft():
x1=x1-(x2图像宽度)
x2=图像宽度
打印(“向左移动!”)
错误消息如下所示:

文件“image\u import2.py”,第121行
如果(y1<0):y_向下移动()
^
SyntaxError:批注的非法目标
有人知道我做错了什么吗?找不到任何关于此类错误的提及…

请看以下几行:

If (y1 < 0): y_movedown()
Elif (y2 > imageheight): y_moveup()
Elif (x1 < 0) : x_moveright()
Elif (x2 > imagewidth): x_moveleft()

相反。

@powderscotty请接受并投票,如果有效,谢谢,很乐意帮助:-),更一般的答案是,在一行的末尾有一个“:”,而该行不是以“if”、“elif”、“else”、“for”等开头。
if (y1 < 0): y_movedown()
elif (y2 > imageheight): y_moveup()
elif (x1 < 0) : x_moveright()
elif (x2 > imagewidth): x_moveleft()