在使用imread函数读取它们时,是否有任何可能的原因在opencv中的jpg文件有一些困难? [英] Is there any possible reason to have some difficulties with jpg files in opencv while using imread function to read them?

查看:542
本文介绍了在使用imread函数读取它们时,是否有任何可能的原因在opencv中的jpg文件有一些困难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在python中使用opencv。



正如我所知,当我想在python中导入 cv2 模块时,我需要将 cv2.so 文件路径添加到系统路径中:

  sys.path.append '/path/to/cv.so')

当我想要读取jpg文件时, ipython笔记本,它失败:

  import sys 
import numpy as np
import os
sys.path.append(/ usr / local / lib1 / python2.7 / site-packages)
import cv2
im1 = cv2.imread('pic1.png')
打印im1.shape
#output :( 512,512,3)
im2 = cv2.imread('pic1.jpg')
打印im2.shape
#output:
----------------------------------------------- --------------------------
AttributeError追溯(最近的最后一次调用)
< ipython-input-8- 2d36ac00eca0>在< module>()
----> 1 print im2.shape
AttributeError:'NoneType'对象没有属性'shape'

基于我以前的问题,我重建了opencv几次。



我阅读了某处可能是一些依赖问题的结果。但是我的系统上有这两个软件包(libjpeg和libjaspe):

  print cv2.getBuildInformation()

媒体I / O:
ZLib:/lib64/libz.so(ver 1.2.8)
JPEG:/lib64/libjpeg.so(ver 80)
WEBP:/ lib64 /libwebp.so(ver编码器:0x0202)
PNG:/lib64/libpng.so(ver 1.6.17)
TIFF:/lib64/libtiff.so(ver 42 - 4.0.2)
JPEG 2000:/lib64/libjasper.so(ver 1.900.1)

任何想法? / p>

解决方案

经过很多努力,我意识到解决方案是添加:

  PYTHONPATH =
export PYTHONPATH
PATH = / usr / bin:/ usr / local / bin
export PATH

/home/.bashrc 文件的末尾(使其永久),$ b运行 python ipython笔记本之前$ b



注意:仅使用 opencv-python.x86_64 (根据您的机器架构)从yum(dnf)存储库(当然为fedora用户)和python 2.7



不要从其网站下载opencv。这有一些依赖性的麻烦,我猜。


Recently, I use opencv in python.

As I noticed, when I want to import cv2 module in python, I need to add cv2.so file path manually to the system paths using:

sys.path.append('/path/to/cv.so')

Howewer, when I want to read jpg files in the ipython notebooks, it fails:

import sys
import numpy as np
import os
sys.path.append("/usr/local/lib1/python2.7/site-packages")
import cv2
im1=cv2.imread('pic1.png')
print im1.shape
#output: (512, 512, 3)
im2=cv2.imread('pic1.jpg')
print im2.shape
#output:
-------------------------------------------------------------------------
AttributeError                         Traceback (most recent call last)
<ipython-input-8-2d36ac00eca0> in <module>()
----> 1 print im2.shape
AttributeError: 'NoneType' object has no attribute 'shape'

Based on my previous question, I rebuilt opencv several times.

I read somewhere that it might be the result of some dependency problems. But I have the both packages (libjpeg and libjaspe) on my system:

print cv2.getBuildInformation()

Media I/O: 
ZLib:                        /lib64/libz.so (ver 1.2.8)
JPEG:                        /lib64/libjpeg.so (ver 80)
WEBP:                        /lib64/libwebp.so (ver encoder: 0x0202)
PNG:                         /lib64/libpng.so (ver 1.6.17)
TIFF:                        /lib64/libtiff.so (ver 42 - 4.0.2)
JPEG 2000:                   /lib64/libjasper.so (ver 1.900.1)

Any idea?

解决方案

After lots of efforts, I realized that the solution is to add:

PYTHONPATH=""
export PYTHONPATH
PATH=/usr/bin:/usr/local/bin
export PATH

at the end of /home/.bashrc file (to make them permanent), before running python or ipython notebook from terminal.

Note: use only opencv-python.x86_64 (based on your machine architecture) from yum (dnf) repository (for fedora users of course!) and python 2.7.

DO NOT download opencv from its website. That makes some dependency troubles, I guess.

这篇关于在使用imread函数读取它们时,是否有任何可能的原因在opencv中的jpg文件有一些困难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆