首页 > 分享 > PIL图像处理时使用np.unit8转化报错: Cannot handle this data type: (1, 1),

PIL图像处理时使用np.unit8转化报错: Cannot handle this data type: (1, 1),

      今天遇上了一个错误,让我折腾了许久:

        详情如下:

Traceback (most recent call last):

File "F:python36libsite-packagesPILImage.py", line 2772, in fromarray

mode, rawmode = _fromarray_typemap[typekey]

KeyError: ((1, 1), '|O')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "main.py", line 117, in <module>

main()

File "main.py", line 79, in main

one_judge=recognition.singleJudge(frame,one_box)

File "F:projectrecognition.py", line 100, in singleJudge

one_judge=modelPredict(classifyModel,one_cut_img)

File "F:projectrecognition.py", line 73, in modelPredict

image = loadSingleImage(img)

File "F:projectrecognition.py", line 59, in loadSingleImage

image = np.array(Image.fromarray(np.array(img)).resize((224, 224)))

File "F:python36libsite-packagesPILImage.py", line 2774, in fromarray

raise TypeError("Cannot handle this data type: %s, %s" % typekey) from e

TypeError: Cannot handle this data type: (1, 1), |O

          查了一下网上的资料,找到一个解决办法说是在使用Image.fromarray方法的时候对数据进行限定,加入np.unit8,我加入之后依旧报错,报错如下:

       详情如下:

Traceback (most recent call last):

File "main.py", line 117, in <module>

main()

File "main.py", line 79, in main

one_judge=recognition.singleJudge(frame,one_box)

File "F:projectrecognition.py", line 100, in singleJudge

one_judge=modelPredict(classifyModel,one_cut_img)

File "F:projectrecognition.py", line 73, in modelPredict

image = loadSingleImage(img)

File "F:projectrecognition.py", line 61, in loadSingleImage

image = np.array(Image.fromarray(np.uint8(np.array(img))).resize((224, 224)))

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Image'

       经过几次改动尝试后,最终的解决方法如下:

data = np.array(img.resize([width, height]),np.uint8(Image.BILINEAR))

image = np.array(Image.fromarray(np.uint8(data)))

        记录一下备忘。

相关知识

成功解决报错Cannot find class [com.alibaba.druid.pool.DruidDataSource] for bean with name ‘dataSource‘
基于TensorFlow的CNN卷积网络模型花卉分类(1)
【北京大学】13 TensorFlow1.x的项目实战之手写英文体识别OCR技术
深度学习实战(二):AlexNet实现花图像分类
onclick触发type=file并上传文件
深度学习实战:AlexNet实现花图像分类
CUBEAI详细使用教程(STM32运行神经网络)
使用 IBM Data Studio 管理数据库最佳实践1
基于Tensorflow使用CNN进行图像分类
y=ln(x+3),x0=1,求方程的根,用牛顿法。我的答案总乱码啊,为什么

网址: PIL图像处理时使用np.unit8转化报错: Cannot handle this data type: (1, 1), https://m.huajiangbk.com/newsview1222724.html

所属分类:花卉
上一篇: 200多个蔬菜新优品种,全在这!
下一篇: 种凤仙花需要什么工具