Code completion does not work for OpenCV and Python

I am using Ubuntu 14.04. I installed OpenCV using the Adrian Rosebrock tutorial. I also use PyCharm for programming python and opencv.

My problem is that I can use code completion for cv2 modules, but code completion will not work for instances initiated by cv2. An example is shown below.

This file works.

But that would not be.

Runtime error while writing my program, as expected. Thus, cap.isOpened () works without errors.

+8
python opencv code-completion intellisense
source share
1 answer

The python openCV module is a dynamically created wrapper for the C ++ core library. PyCharm relies on the availability of python source code to provide autocomplete functionality. When the source code is missing (as is the case with opencv), pycharm will generate skeletal files with function prototypes and rely on those used for autocompletion, but with reduced capabilities.

As a result, when you autofill

cv2. 

you can understand that the cv2 module has the following members and provides suggestions.

On the other hand, when you

 cap = cv2.VideoCapture(file_name) 

PyCharm can understand that you just called a method from the cv2 module and assigned its cap , but you don’t have information about the type of the result of this method and you don’t know where to look for searches for

 cap. 

If you try the same things in shell mode, you will see the behavior that you actually expect to see, since in shell mode there will actually be an introspection of living objects (he will ask the created cover object what members he has and provide them as suggestions)


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

Look here

+4
source share

All Articles