简体   繁体   English

为什么Python cv2模块依赖于(旧)cv

[英]Why does Python cv2 modules depend on (old) cv

I'm new to OpenCV and would like to use its Python binding. 我是OpenCV的新手,想使用它的Python绑定。

When trying out the samples on OSX, I noticed 在OSX上试用样品时,我注意到了

1.) The windows imshow creates are not resizable 1.)窗口imshow创建的不可调整大小

2.) I can fix that with an prior call to cv2.namedWindow, like: cv2.namedWindow('zoom', cv2.cv.CV_WINDOW_NORMAL) 2.)我可以通过事先调用cv2.namedWindow来修复它,例如:cv2.namedWindow('zoom',cv2.cv.CV_WINDOW_NORMAL)

Can we add symbols like CV_WINDOW_NORMAL from cv into cv2 !? 我们可以将cv中的CV_WINDOW_NORMAL等符号添加到cv2中吗? Who has commit rights to openCV's Python binding ? 谁拥有openCV Python绑定的权利?

Thanks, Sebastian Haase 谢谢,Sebastian Haase

There are some omisions in the current new cv2 lib. 当前的新cv2 lib中有一些省略。 Typically these are constants that did not get migrated to cv2 yet and are still in cv only. 通常这些是尚未迁移到cv2但仍仅在cv中的常量。 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]

cv2 is a more faithful wrapper around the C++ libs than the previous cv. cv2是比以前的cv更加忠实的C ++库包装器。 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. 代码更容易阅读,numpy矩阵操作非常快。

I suggest you find and use the cv constants while reporting their omissions as bugs to the opencv bug tracker at willowgarage. 我建议你找到并使用cv常量,同时向willowgarage的opencv bug跟踪器报告它们的遗漏。 cv2 is fresh and minty but will improve. cv2是新鲜的薄荷,但会改善。

FYI. 仅供参考。 it is well worth instantiating the named windows before use, also killing them on exit. 在使用之前很好地实例化命名窗口,并在退出时杀死它们。 IMHO 恕我直言

Eg 例如

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM