Can the superres module in OpenCV only be used in C++?

I have built OpenCV4 on Windows 11. When I attempt to use the superres module by Python, I encountered an error: module 'cv2' has no attribute 'superres'

import cv2
model = cv2.superres.createSuperResolution_BTVL1()

I had included the superres module when building OpenCV.

Cmake info:

Then I found using C++ is ok. So can this module only be used in C++?

#include <iostream>
#include <cstring>
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp" 
#include "opencv2/superres.hpp"

int main(int argc, char* argv[])
{
        // no error.
    cv::superres::createSuperResolution_BTVL1();
    return 0;
}

4

The Python wrappers for OpenCV are generally automatically generated (there are some hand-written ones, but that’s a tiny fraction). In order for this to happen, annotations in form of macros have to present in the header file(s) of the respective module. For free-standing functions and classes this is usually CV_EXPORTS_W and friends, for class member functions some variation of CV_WRAP, and there are some more that may need to be used for function arguments. I’ve described a few in an answer to this question, and the OpenCV documentation contains some useful bits as well.

If we examine the header of superres module, we can se no such annotations (CV_EXPORTS is just a generic export/import doohickey, no wrappers are generated there). The superres module was moved out from main to contrib during transition to 4.0, apparently due to lack of maintenance. When I look at the 3.x branch, I can’t find any annotations either. I didn’t dig any deeper, so who knows, it might have had something available in 2.x, but that’s not really relevant today.

Generally, when Python wrappers are generated, so is a function signature for the documentation. None can be seen in the documentation, so that’s some more evidence to support our conclusion.


Based on the above, this module’s functionality is not available in the standard Python bindings for OpenCV. That does not necessarily mean it’s available only from C++, since some bindings for other languages are implemented differently, but since this is an unmaintained contrib module, it’s likely the case.

Possible solutions:

  • As Christoph mentioned, have a look at dnn_superres — that has Python bindings available.
  • Adding the annotations to superres likely wouldn’t be too difficult, if you took inspiration from some other modules that have them on classes. I have no idea how easy it would be to get such a pull request accepted there, but might be worth a try, unless you want to ship your own custom build with your program.
  • I suppose you could try to use it via ctypes, but given it’s C++, it’s like opening another can of worms, and portability goes outta the window.
  • You could write a thin wrapper around the needed functionality using Boost.Python or pybind11. Both have support for numpy arrays, so it shouldn’t be too hard to make it play nice with regular OpenCV Python code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật