PIL无法处理uvccapture生成的图像(PIL can not deal with images generated by uvccapture)

系统教程 行业动态 更新时间:2024-06-14 16:58:29
PIL无法处理uvccapture生成的图像(PIL can not deal with images generated by uvccapture)

我使用uvccapture拍照并希望在python和python imaging library (PIL)的帮助下处理它们。 问题是PIL无法打开这些图像。 它抛出以下错误消息。

Traceback (most recent call last): File "process.py", line 6, in <module> im = Image.open(infile) File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1980, in open raise IOError("cannot identify image file") IOError: cannot identify image file

我的python代码如下所示:

import Image infile = "snap.jpg" im = Image.open(infile)

在处理之前,我尝试以不同的格式保存图像。 但这没有用。 同时更改文件权限和所有者也无济于事。 唯一jpegoptim是打开图像,例如使用jpegoptim ,并用优化的图像覆盖旧图像。 在此过程之后, PIL可以处理这些图像。

这里有什么问题? uvccapture生成的文件是否uvccapture损坏?

//编辑:我也发现,用scipy打开用uvccapture生成的图像是不可能的。 运行命令

im = scipy.misc.imread("snap.jpg")

产生相同的错误。

IOError: cannot identify image file

I use uvccapture to take pictures and want to process them with the help of python and the python imaging library (PIL). The problem is that PIL can not open those images. It throws following error message.

Traceback (most recent call last): File "process.py", line 6, in <module> im = Image.open(infile) File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1980, in open raise IOError("cannot identify image file") IOError: cannot identify image file

My python code looks like this:

import Image infile = "snap.jpg" im = Image.open(infile)

I tried to save the images in different formats before processing them. But this does not help. Also changing file permissions and owners does not help. The only thing that helps is to open the images, for example with jpegoptim, and overwriting the old image with the optimized one. After this process, PIL can deal with these images.

What is the problem here? Are the files generated by uvccapture corrupt?

//EDIT: I also found out, that it is not possible to open the images, generated with uvccapture, with scipy. Running the command

im = scipy.misc.imread("snap.jpg")

produces the same error.

IOError: cannot identify image file

最满意答案

我只找到了解决这个问题的方法。 我使用jpegoptim处理捕获的图片,然后PIL可以处理优化的图像。

I only found a workaround to this problem. I processed the captured pic with jpegoptim and afterwords PIL could deal with the optimized image.

更多推荐

本文发布于:2023-04-15 03:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/cfc115785ddc3e7d54696b49d8040662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   uvccapture   PIL   generated   images

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!