ubuntu opencv unufree SIFT算子使用方法

for debian users its 'easy' to create their own libopencv-nonfree package.

i followed the opencv tutorial for python, but in my debian the SIFT and SURF modules were missing. And there is no non-free package available for debian including SIFT and SURF etc.

They were stripped from the package due to license issues....

i never created a package for debian before (adding a new module etc) but i followed some small steps in the debian tutorials and tried and guessed around a bit, and after 1 day, voila... i got working a libopencv-nonfree2.4 deb package and a python module with correct bindings.

(i dont know if i also needed to install the newly built python-opencv package or only the nonfree... i re-installed both and got a working python opencv library with all necessary nonfree modules!)

ok, here it is:

!this is for libopencv 2.4!

!you can do all steps except installing as a normal user!

we need the built essesntials and some tools from debian repository to compile and create a new package:

sudo apt-get install build-essential fakeroot devscripts

create a directory in your home and change to that directory:

cd ~ && mkdir opencv-debian
cd opencv-debian

download the needed packages:

apt-get source libopencv-core2.4

and download all needed dependency packages to build the new opencv

apt-get build-dep libopencv-core2.4

this will download the neeeded sources and create a directory called "opencv-2.4.9.1+dfsg"

change to that directory:

cd opencv-2.4.9.1+dfsg

now you can test if the package will built without modifications by typing:

fakeroot debian/rules binary

this will take a long time! this step should finish without errors you now have a lot of .deb packages in your opencv-debian directory

now we make some modifications to the package definition to let debian buld the nonfree modules and package!

change to the opencv-debian directory and download the correct opencv source.. in my case opencv 2.4.9 or so

i got mine from https://github.com/Itseez/opencv/releases

wget https://codeload.github.com/Itseez/opencv/tar.gz/2.4.9

this will download opencv-2.4.9.tar.gz

extract the archive:

tar -xzvf opencv-2.4.9.tar.gz

this will unpack the original source to a directory called opencv-2.4.9

now copy the nonfree modules from original source to the debian source:

cp -rv opencv-2.4.9/modules/nonfree opencv-2.4.9.1+dfsg/modules/

ok, now we have the source of the nonfree modules, but thats not enough for debian... we need to modify 1 file and create a new one

we have to edit the debian control file and add a new section at end of file: (i use mcedit as an editor here)

mcedit opencv-2.4.9.1+dfsg/debian/control

or use any other editor of your choice

and add this section:

Package: libopencv-nonfree2.4
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: OpenCV Nonfree Modules like SIFT and SURF
 This package contains nonfree modules for the OpenCV (Open Computer Vision)
 library.
 .
 The Open Computer Vision Library is a collection of algorithms and sample
 code for various computer vision problems. The library is compatible with
 IPL (Intel's Image Processing Library) and, if available, can use IPP
 (Intel's Integrated Performance Primitives) for better performance.
 .
 OpenCV provides low level portable data types and operators, and a set
 of high level functionalities for video acquisition, image processing and
 analysis, structural analysis, motion analysis and object tracking, object
 recognition, camera calibration and 3D reconstruction.

now we create a new file called libopencv-nonfree2.4.install

touch opencv-2.4.9.1+dfsg/debian/libopencv-nonfree2.4.install

and edit:

mcedit opencv-2.4.9.1+dfsg/debian/libopencv-nonfree2.4.install

and add the following content:

usr/lib/*/libopencv_nonfree.so.*

ok, thats it, now create the packages again:

cd opencv-2.4.9.1+dfsg

first a clean up:

fakeroot debian/rules clean

and build:

fakeroot debian/rules binary

et voila... after a while you have a fresh built and a new package libopencv-nonfree2.4.deb!

now install as root:

dpkg -i libopencv-nonfree2.4.deb
dpkg -i python-opencv.deb

此处会有一些问题,

root@bond-pc:~/opencv-debian# dpkg -i libopencv-nonfree2.4_2.4.8+dfsg1-2ubuntu1_amd64.deb 
Selecting previously unselected package libopencv-nonfree2.4.
(Reading database ... 225771 files and directories currently installed.)
Preparing to unpack libopencv-nonfree2.4_2.4.8+dfsg1-2ubuntu1_amd64.deb ...
Unpacking libopencv-nonfree2.4 (2.4.8+dfsg1-2ubuntu1) ...
dpkg: dependency problems prevent configuration of libopencv-nonfree2.4:
 libopencv-nonfree2.4 depends on libopencv-ocl2.4; however:
  Package libopencv-ocl2.4 is not installed.


dpkg: error processing package libopencv-nonfree2.4 (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 libopencv-nonfree2.4


这个错误,原因是缺少的那个 libopencv-nonfree2.4没有安装,先去/opencv-debian#文件夹下,把libopencv-ocl2.4_2.4.8+dfsg1-2ubuntu1_amd64.deb用dpkg执行下,就可以去掉这个错误了

不同的生成的文件名可能会有些区别,所以要去opencv-debian下自己找相对应的文件,就可以了

and test!

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('test.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

sift = cv2.SIFT()
kp = sift.detect(gray,None)
img=cv2.drawKeypoints(gray,kp)

corners = cv2.goodFeaturesToTrack(gray,16,0.05,10)
corners = np.int0(corners)

for i in corners:
    x,y = i.ravel()
    cv2.circle(img,(x,y),90,255,3)

plt.imshow(img),plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值