Solve the problem of opencv code completion

There are countless stepped pits, hereby record the
original text from: https://blog.csdn.net/qq_36735489/article/details/82110972

1. Problem description:

Completion of opencv functions in pycharm is very convenient. Ctr+left click can view the source code, but the completion of opencv is often abnormal. Here is a measured and effective solution

2. Environment

windows10,opencv4.4,pycharm,anaconda3

3. Solution

1. Install opencv

pip install opencv-python
conda install opencv-python

2. Modify the configuration file

  • Find your python site-packages folder, open the __init__.py file of opencv,
  • Modify the __init__.py file. For example, if you install annaconda, then it will be the xxx\Anaconda3\Lib\site-packages\cv2_ init _.py file, comment out the original code (you can delete it), and change it to
import sys
import os
import importlib
os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__))
from .cv2 import *
globals().update(importlib.import_module('cv2.cv2').__dict__)
  • Note that you need to wait for pycharm to reload the configuration file in the directory before it can take effect.

3. Measured results

  • Insert picture description here

Guess you like

Origin blog.csdn.net/ca___0/article/details/108899987