Python, opencv, cv2

文章来源:http://blog.csdn.net/summermaoz/article/details/67637325


将代码放在师姐电脑上跑的时候,用的是python2.7

出现cv2.cv,没有cv这个属性,在命令行import cv 时出错,没有cv这个module,但是可以import cv2,解决方式是下载安装opencv。

1、两个下载模块的地址: https://pypi.python.org/pypi

2、介绍cv:  http://www.programcreek.com/python/index/413/cv

安装cv2模块:whl文件可以

安装cv模块(可以不要cv模块)
opencv版本问题,3.x不能cv2.cv, 2.x可以
例子:
           videocapture = cv2.VideoCapture(VideoFile)
安装cv:    fps = videocapture.get(cv2.cv.CV_CAP_PROP_FPS)
未安装从v:fps = videocapture.get(cv2.CAP_PROP_FPS)


3、两者区别:

cv2扩展库是针对OpenCV 2.x API创建的,直接采用NumPy的数组对象表示图像,和pyopencv相比,不再需要在数组和Mat对象之间相互转换了。

cv2的函数直接对Numpy数组进行操作,

cv2读取图像是数组,array = cv2.imread()


(1)cv读取图像:

①iplimage = cv.LoadImage()  

<type 'cv2.cv.iplimage'>

<iplimage(nChannels=3 width=1212 height=824 widthStep=3636 )>

②cvmat = cv.LoadImageM()

<type 'cv2.cv.cvmat'>

<cvmat(type=42424010 8UC3 rows=824 cols=1212 step=3636 )>


(2)array, iplimage, cvmat 转换

array------>     cvmat:        cv.fromarray(array)

cvmat------>    array:         np.asarray(cvamt)

cvmat------>    iplimage:    cv.GetImage(cvmat)  

iplimage---->   cvmat:       iplimage[:], 或 cv.GetMat(iplimage)

猜你喜欢

转载自blog.csdn.net/w_han__/article/details/78963707