在获取OpenCV的过程中经历了一段糟糕的时光

2024-04-19 15:06:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试按照本教程使用python/opencv来计算从相机到对象的距离:http://www.pyimagesearch.com/2015/01/19/find-distance-camera-objectmarker-using-python-opencv/

我在一个ubuntu盒子上。我用pip超级容易地安装了numpy,但是为了让opencv工作我花了很多时间。我阅读了本文,从源代码处安装了它:http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/

一切似乎都安装正确。。。当我运行dpkg -l | grep libopencv ii libopencv-calib3d2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Camera Calibration library ii libopencv-contrib2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision contrib library ii libopencv-core2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision core library ii libopencv-features2d2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Feature Detection and Descriptor Extraction library ii libopencv-flann2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Clustering and Search in Multi-Dimensional spaces library ii libopencv-highgui2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision High-level GUI and Media I/O library ii libopencv-imgproc2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Image Processing library ii libopencv-legacy2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision legacy library ii libopencv-ml2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Machine Learning library ii libopencv-objdetect2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Object Detection library ii libopencv-photo2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision computational photography library ii libopencv-video2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Video analysis library

但是当我下载源代码并从第一个链接运行代码时,我得到了以下错误:

OpenCV Error: Assertion failed (step[dims-1] == (size_t)CV_ELEM_SIZE(flags)) in create, file /home/nitrous/opencv-2.4.9/modules/core/src/matrix.cpp, line 236 Traceback (most recent call last): File "distance_to_camera.py", line 41, in <module> marker = find_marker(image) File "distance_to_camera.py", line 16, in find_marker (cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) cv2.error: /home/nitrous/opencv-2.4.9/modules/core/src/matrix.cpp:236: error: (-215) step[dims-1] == (size_t)CV_ELEM_SIZE(flags) in function create


Tags: andincorelibraryfindcv2opencvamd64
1条回答
网友
1楼 · 发布于 2024-04-19 15:06:29

使用包管理器:

sudo apt-get install python-opencv

如果需要python3版本,请将其更改为python3opencv。它将为您安装所有依赖项,包括python numpy。你知道吗

请不要将pip用于aptitude中的全局包,如果您使用pip(如上所示),这些包将由系统和YMMV处理。如果您想使用pip,请创建一个virtualenv来安装各个包。你知道吗

对于任何未来的软件包,要检查软件包是否在aptitude中可用,只需运行:

apt-cache search python-{package}

或者

apt-cache search python3-{package}

这将让您知道是否有任何安装候选人。如果有一个-dev版本的包可用,您可能还需要安装它。你知道吗

相关问题 更多 >