代码完成不适用于OpenCV和Python [英] Code completion is not working for OpenCV and Python

查看:95
本文介绍了代码完成不适用于OpenCV和Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ubuntu 14.04.我已经使用Adrian Rosebrock的指南安装了OpenCV.我也正在使用PyCharm来编程python和opencv.

I am using Ubuntu 14.04. I have installed OpenCV using Adrian Rosebrock's guide. I am also using PyCharm for programming python and opencv.

我的问题是我可以对cv2模块使用代码完成功能,但是代码完成功能不适用于从cv2启动的实例.下面显示了一个示例.

My problem is that I can use code completion for cv2 modules but code completion wont work for instances initiated from cv2. An example is shown below.

此方法有效.

但这不是.

按预期编写程序时没有运行时错误.这样 cap.isOpened()可以正常运行.

There is no run time error when I write my program as expected. Such that cap.isOpened() works without an error.

推荐答案

openCV python模块是

The openCV python module is a dynamically generated wrapper of the underlying c++ library. PyCharm relies on the availability of python source code to provide autocomplete functionality. When the source code is missing (as in the opencv case), pycharm will generate skeleton files with function prototypes and rely on those for autocompletion but with diminished capabilities.

当您在

cv2.

它可以确定模块cv2具有以下成员并提供建议.

it can figure out that the module cv2 has the following members and provide suggestions.

另一方面,当您

cap = cv2.VideoCapture(file_name)

PyCharm可以确定您只是从cv2模块中调用了一个方法,并将其分配给了cap,但是没有有关该方法的结果类型的信息,并且不知道去哪里寻找建议

PyCharm can figure out that you just called a method from the cv2 module and assigned it to cap but has no information about the type of the result of this method and does not know where to go look for suggestions for

cap.


如果您在Shell模式下尝试相同的操作,您将看到您实际上预期会看到的行为,因为在Shell模式下,实际上将对活动对象进行内省(它将询问已创建的cap对象具有哪些成员,并提供这些建议作为建议. )


If you try the same things in shell mode, you will see the behavior you actually expected to see, since in shell mode will actually introspect live objects (it will ask the created cap object what members it has and provide those as suggestions)

您还可以自己编写opencv模块的存根,以在编辑模式下启用正确的自动补全功能.

You can also write stubs for the opencv module yourself to enable correct autocompletion in edit mode.

此处

这篇关于代码完成不适用于OpenCV和Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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