我已经尝试了很多方法,包括从源代码构建(包括opencv和ffmpeg以及编解码器),但似乎没有任何帮助。我有一个mp4文件,在python2.7环境下可以正常工作,但是在python3.5中无法加载。
我知道我安装了不同的版本,但是我不明白为什么opencv无法为python3.5环境加载。我检查了路径等,没发现什么问题。
Python 2.7.12:
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.1'
>>> a=cv2.VideoCapture("Serenity.mp4")
>>> a.isOpened()
True
Python 3.5.2:
^{pr2}$我已经完成了以下工作:
视频样本信息:
ffprobe version 3.4 Copyright (c) 2007-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 20160609
configuration: --enable-pic
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3d57b00] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Serenity.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isomavc1
creation_time : 2007-05-30T05:20:31.000000Z
genre : Trailer
artist : Universal Pictures
title : Serenity - HD DVD Trailer
date : 2005
Duration: 00:02:19.71, start: 0.000000, bitrate: 4802 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 4674 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
creation_time : 2007-05-30T05:20:31.000000Z
handler_name : GPAC ISO Video Handler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
creation_time : 2007-05-30T05:20:34.000000Z
handler_name : GPAC ISO Audio Handler
Stream #0:2: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 240x240 [SAR 1:1 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
编辑:我还尝试过从源代码处编译,根据注释中的建议(并交换.so文件): https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
解决方法:经过多次尝试,我不得不清除我的lubuntu16.04.3系统并重新构建它。请参阅下面的详细答案。
在新安装了lubuntu并添加了dev包之后,我成功地编译了opencv 3.3.1,然后打开了python3:
报告的3.3.0是错误的
^{pr2}$告诉我导入位置,所以我将其重命名为cv2.cpython-35m-x86_64-linux-gnu.so.旧. 然后使用
我找到了我刚刚构建的一个,并将其移动到cv2中。文件位置,这个方法奏效了。在
FYI还使用以下一组命令编译了opencv:
相关问题 更多 >
编程相关推荐