开发者

ImageChops.duplicate - python

I am tring to use the function ImageChops.dulpicate from the PIL module and I get an error I don't understand:

this is the code

import PIL
import Image
import ImageChops
import os

PathDemo4a='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/demo4a'
PathDemo4b='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/demo4b'
PathDemo4c='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/demo4c'
PathBlackBoard='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/BlackBoard.bmp'

Slides=os.listdir(PathDemo4a)

for slide in Slides:
    #BB=Image.open(PathBlackBoard)
    BB=ImageChops.duplicate(PathBlackBoard) #BB=BlackBoard

and this is the error;

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    ImageChops.duplicate('c:/1.BMP')
  File "C:\Python26\lib\site-packages\PIL\ImageChops.py", line 57, in duplicate
    return image.copy()
Attrib开发者_StackOverflow中文版uteError: 'str' object has no attribute 'copy'

any help would be much appriciated

Ariel


You need to pass a Image object into the duplicate function rather than a string. Something like:

img = Image.open(PathBlackBoard)
BB = ImageChops.duplicate(img) 


I think you should pass an actual image object to duplicate and not a string. So your code will probably become something like this for one image:

path = '...'
img = Image.open(path)
dup = ImageChops.duplicate(img)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜