在 Ubuntu 14.0 上安装 Opencv 2.0 时出现问题

在 Ubuntu 14.0 上安装 Opencv 2.0 时出现问题

我在 Ubuntu 14.04 上尝试安装 OpenCV 2.0 时遇到问题。当我想安装依赖项时,我遇到了以下问题:

andres@andres-VirtualBox:~$ sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
[sudo] password for andres:
Reading package lists...
Done Building dependency tree  Reading state information...
Done Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created or been
moved out of Incoming. The following information may help to resolve the
situation:

The following packages have unmet dependencies:
libtiff4-dev : Depends: libtiff5-dev (> 4.0.3-6~) but it is not going to be installed 
E: Unable to correct problems, you have held broken packages.

我想安装 OpenCV 2.0,因为有一个旧项目使用该版本的 OpenCV。

更新 1

1:我安装了 libtiff5-dev,但它又抛出了另一个错误:

The following packages have unmet dependencies:
 libjpeg-turbo8-dev : Conflicts: libjpeg62-dev but 6b1-4ubuntu1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

然后我删除了 libjpeg-turbo8-dev,但它卸载了 libtiff5-dev。大约 4 年前有人发帖提到了这个问题,但没有解决方案:

http://ubuntuforums.org/showthread.php?t=1985957

更新 2

我使用 aptitude 而不是 apt-get 来安装依赖项。一切顺利,但我检查了 ffmpeg 和 v4l 是否为 no。我不在意,尝试编译库。我收到以下编译错误:

In file included from ../include/opencv/cxcore.h:2123:0,
                 from cxcore/_cxcore.h:60,
                 from cxcore/cxprecomp.cpp:43:
../include/opencv/cxcore.hpp:169:13: error: ‘ptrdiff_t’ does not name a type
     typedef ptrdiff_t difference_type;
             ^
In file included from ../include/opencv/cxcore.hpp:2243:0,
                 from ../include/opencv/cxcore.h:2123,
                 from cxcore/_cxcore.h:60,
                 from cxcore/cxprecomp.cpp:43:
../include/opencv/cxoperations.hpp:1916:15: error: ‘ptrdiff_t’ does not name a type
 static inline ptrdiff_t operator - (const FileNodeIterator& it1, const FileNodeIterator& it2)
               ^
../include/opencv/cxoperations.hpp:2465:31: error: ‘ptrdiff_t’ does not name a type
 template<typename _Tp> inline ptrdiff_t operator - (const SeqIterator<_Tp>& a,
                               ^
In file included from ../include/opencv/cxcore.hpp:2244:0,
                 from ../include/opencv/cxcore.h:2123,
                 from cxcore/_cxcore.h:60,
                 from cxcore/cxprecomp.cpp:43:
../include/opencv/cxmat.hpp: In member function ‘void cv::Mat::locateROI(cv::Size&, cv::Point&) const’:
../include/opencv/cxmat.hpp:356:5: error: ‘ptrdiff_t’ was not declared in this scope
     ptrdiff_t delta1 = data - datastart, delta2 = dataend - datastart;
     ^
../include/opencv/cxmat.hpp:356:5: note: suggested alternatives:
In file included from /usr/include/c++/4.8/utility:68:0,
                 from /usr/include/c++/4.8/algorithm:60,
                 from ../include/opencv/cxcore.hpp:51,
                 from ../include/opencv/cxcore.h:2123,
                 from cxcore/_cxcore.h:60,
                 from cxcore/cxprecomp.cpp:43:
/usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h:187:28: note:   ‘std::ptrdiff_t’
   typedef __PTRDIFF_TYPE__ ptrdiff_t;
                            ^
/usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h:187:28: note:   ‘std::ptrdiff_t’
In file included from ../include/opencv/cxcore.hpp:2244:0,
                 from ../include/opencv/cxcore.h:2123,
                 from cxcore/_cxcore.h:60,
                 from cxcore/cxprecomp.cpp:43:
../include/opencv/cxmat.hpp:356:15: error: expected ‘;’ before ‘delta1’
     ptrdiff_t delta1 = data - datastart, delta2 = dataend - datastart;
               ^
../include/opencv/cxmat.hpp:358:9: error: ‘delta1’ was not declared in this scope
     if( delta1 == 0 )
         ^
../include/opencv/cxmat.hpp:367:31: error: ‘delta2’ was not declared in this scope
     wholeSize.height = (int)((delta2 - minstep)/step + 1);
                               ^
make[2]: *** [cxprecomp.lo] Error 1
make[2]: Leaving directory `/home/andres/OpenCV-2.0.0/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/andres/OpenCV-2.0.0'
make: *** [all] Error 2

答案1

我已经在全新安装的 Ubuntu 12.04 和 14.04 上测试过,两者都给出了几乎相同的错误。错误关于ibjpeg-turbo8-dev : Conflicts: libjpeg62-dev

如果您正在使用虚拟机,并且不怕损坏它您可以尝试运行此命令。接受所有aptitute建议并继续执行结果。

sudo aptitude install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

更新

通过 aptitude 安装后,OP 出现编译问题。此问题已通过评论中@steeldriver 的建议解决:

尝试编辑包的 include/opencv/cxcore.hpp 文件并将其添加#include <cstddef>到其标准标头列表中:请参阅此处http://code.opencv.org/issues/1028

相关内容