Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

setting an array element with a sequence error (Programming computer vision in with python book)

I just follow the exercise from the book called Programming computer vision in with python. I'm trying to execute the following code but it give me errors.

from PIL import Image 
from numpy import * 
from pylab import * 
import imtools 
import pca

# Uses dense pca codepath.
imlist = imtools.get_imlist('D:Programming computer vision with pythonBasic image handling and processingData1')

im = array(Image.open(imlist[0]))  #open one image to get size 

m,n = im.shape[0:2] # get the size of the images 

imcount = len(imlist) # get the number of images

# create matrix to store all flattened images
immatrix = array([array(Image.open(im)).flatten() for im in imlist], "f")

# perform PCA
V, S, immean = pca.pca(immatrix)

# show some images (mean and 7 first modes)
figure() 

gray() 

subplot(2, 4, 1) 

imshow(immean.reshape(m,n)) 

for i in range(7): 

    subplot(2, 4, i+2) 

    imshow(V[i].reshape(m,n))

show()

when i compile this code it gives me this error:

immatrix = array([array(Image.open(im)).flatten() for im in imlist], "f") ValueError: setting an array element with a sequence. 

What should I do?

question from:https://stackoverflow.com/questions/65652008/setting-an-array-element-with-a-sequence-error-programming-computer-vision-in-w

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...