Rascberry上的opencv-3.0.0错误

时间:2017-04-24 11:24:13

标签: python c++

我在rasperry Pi上的Opencv-3.0.0中出现此错误

enter cod# OpenCV_test1.py

此程序以相同的目录名打开文件" image.jpg"并显示原始图像和原始图像的Canny边缘

导入cv2 导入numpy为np import os

def main():     imgOriginal = cv2.imread(" image.jpg")#open image

if imgOriginal is None:                             # if image was not read successfully
    print "error: image not read from file \n\n"        # print error message to std out
    os.system("pause")                                  # pause so user can see error message
    return                                              # and exit function (which exits program)
# end if

imgGrayscale = cv2.cvtColor(imgOriginal, cv2.COLOR_BGR2GRAY)        # convert to grayscale

imgBlurred = cv2.GaussianBlur(imgGrayscale, (5, 5), 0)              # blur

imgCanny = cv2.Canny(imgBlurred, 100, 200)                          # get Canny edges

cv2.namedWindow("imgOriginal", cv2.WINDOW_AUTOSIZE)        # create windows, use WINDOW_AUTOSIZE for a fixed window size
cv2.namedWindow("imgCanny", cv2.WINDOW_AUTOSIZE)           # or use WINDOW_NORMAL to allow window resizing

cv2.imshow("imgOriginal", imgOriginal)         # show windows
cv2.imshow("imgCanny", imgCanny)

cv2.waitKey()                               # hold windows open until user presses a key

cv2.destroyAllWindows()                     # remove windows from memory

return

如果名称 ==" 主要":     main()的

这里

这就是错误 python OpenCV_test1.py   文件" OpenCV_test1.py",第4行     导入cv2 import numpy as np import os                     ^ SyntaxError:语法无效

1 个答案:

答案 0 :(得分:0)

导入必须分开(或用分号分隔,但请不要)。

更改

import cv2 import numpy as np import os

import cv2
import numpy as np
import os