为什么Python cv2模块依赖于(旧的)cv [英] Why does Python cv2 modules depend on (old) cv

查看:99
本文介绍了为什么Python cv2模块依赖于(旧的)cv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenCV的新手,并且想使用它的Python绑定.

I'm new to OpenCV and would like to use its Python binding.

在OSX上试用样本时,我注意到

When trying out the samples on OSX, I noticed

1.)imshow创建的窗口无法调整大小

1.) The windows imshow creates are not resizable

2.)我可以通过事先调用cv2.namedWindow来解决此问题,例如: cv2.namedWindow('zoom',cv2.cv.CV_WINDOW_NORMAL)

2.) I can fix that with an prior call to cv2.namedWindow, like: cv2.namedWindow('zoom', cv2.cv.CV_WINDOW_NORMAL)

我们可以从cv向cv2中添加诸如CV_WINDOW_NORMAL之类的符号吗? 谁拥有对openCV的Python绑定的提交权?

Can we add symbols like CV_WINDOW_NORMAL from cv into cv2 !? Who has commit rights to openCV's Python binding ?

谢谢, 塞巴斯蒂安·哈斯(Sebastian Haase)

Thanks, Sebastian Haase

推荐答案

当前新的cv2库中存在一些遗漏.通常,这些是尚未迁移到cv2的常量,仅在cv中存在. 这是一些代码来帮助您找到它们:

There are some omisions in the current new cv2 lib. Typically these are constants that did not get migrated to cv2 yet and are still in cv only. Here is some code to help you find them:

import cv2
import cv2.cv as cv
nms  = [(n.lower(), n) for n in dir(cv)] # list of everything in the cv module
nms2 = [(n.lower(), n) for n in dir(cv2)] # list of everything in the cv2 module

search = 'window'

print "in cv2\n ",[m[1] for m in nms2 if m[0].find(search.lower())>-1]
print "in cv\n ",[m[1] for m in nms if m[0].find(search.lower())>-1]

与以前的cv相比,cv2是C ++库的更忠实的包装器.我一开始发现它令人困惑,但是一旦您进行更改,它就会容易得多.该代码更易于阅读,并且对numpy的矩阵操作非常快.

cv2 is a more faithful wrapper around the C++ libs than the previous cv. I found it confusing at first but it is much easier once you make the change. The code is much easier to read and numpy matrix manipulations are very fast.

我建议您在将cv常数作为bug的遗漏报告给willowgarage的opencv bug跟踪程序时,找到并使用cv常数. cv2新鲜又有薄荷味,但会改善.

I suggest you find and use the cv constants while reporting their omissions as bugs to the opencv bug tracker at willowgarage. cv2 is fresh and minty but will improve.

仅供参考.值得在使用之前实例化命名的窗口,并在退出时将其杀死.恕我直言

FYI. it is well worth instantiating the named windows before use, also killing them on exit. IMHO

例如

import cv2
if __name__ == '__main__': 
    cap = cv2.VideoCapture(0) # webcam 0
    cv2.namedWindow("input")
    cv2.namedWindow("grey")
    key = -1
    while(key < 0):
        success, img = cap.read()
        cv2.imshow("input", img)
        grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        cv2.imshow("grey", grey)
        key = cv2.waitKey(1)
    cv2.destroyAllWindows()

这篇关于为什么Python cv2模块依赖于(旧的)cv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆