惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
小众软件
小众软件
博客园 - 【当耐特】
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
H
Help Net Security
博客园_首页
P
Proofpoint News Feed
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
N
Netflix TechBlog - Medium
爱范儿
爱范儿
MyScale Blog
MyScale Blog
Blog — PlanetScale
Blog — PlanetScale
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
How to Enable Method Autocompletion for OpenCV
2022-11-16 · via jdhao's digital space

Introduction#

In Python, some packages are written mainly or partially in C++, and the Python interfaces are just wrappers around the binary C++ module. Among these packages, there is OpenCV.

When I use python-lsp-server or pyright with Neovim1, I can not get method completion for the OpenCV package. This is because the OpenCV projects is developed using C++ and does not have stub files2 shipped yet.

Using stub file from project python-type-stubs#

Fortunately, the project python-type-stubs provides stub files for several projects including OpenCV. To use the stub file, first find where OpenCV is installed on your system:

python -c 'import os, cv2; print(os.path.dirname(cv2.__file__))'

Then download the stub file and put it in the same directory as OpenCV.

curl -sSL https://raw.githubusercontent.com/microsoft/python-type-stubs/main/cv2/__init__.pyi \
    -o path/to/opencv/directory/__init__.pyi

Then restart nvim, the auto-completion for OpenCV should work as expected.

Using stubgen#

We can also use stubgen to generate the stub files, like this:

# stubgen is installed via mypy package
pip install -U mypy

stubgen -m cv2

The stub file will be saved under the out/ directory. However, the stub file generated by stubgen lacks doc and is not as good as stub file provided by project python-type-stubs.

For more info on using stubgen, visit its page.

References#