简体   繁体   中英

error Opencv 3 in python 3.6.4

I'm just getting started to learning opencv on python I'm using win 10, python 3.6.4 and opencv 3.4 when i want to run this code

image = cv2.imread("lena.jpg")

height, width = image.shape[:2]

quarter_height, quarter_width = height/4, width/4

T = np.float32([[1, 0, quarter_height], [0, 1, quarter_width]])
img_translation = cv2.wrapAffine(image, T, (width, height))
cv2.imshow("Translate", img_translation)
cv2.waitKey(0)
cv2.destroyAllWindows()

this error raised

Traceback (most recent call last):
File "C:\...\PyCharm 2018.1.2\helpers\pydev\pydev_run_in_console.py", line 
52, 
in run_file
pydev_imports.execfile(file, globals, locals)  # execute the script
File "C:\...\PyCharm 2018.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", 
line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Projects/P03/Program.py", line 20, in <module>
main()
File "C:/Projects/P03/Program.py", line 13, in main
img_translation = cv2.wrapAffine(image, T, (width, height))
AttributeError: module 'cv2.cv2' has no attribute 'wrapAffine'

but when i see in dir(cv2) i can find wrapAffine function

i do know how to solve this problem i tried to run the code on several IDEs and python console but nothing happened. please help

You have a typo in your code, or maybe a misunderstanding of the correct term.

The function is warpAffine , not wrapAffine .

  wrapAffine(image, T, (width, height))

The function is warpAffine . This function apply a affine transformation to the image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM