Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
The page contains Frequently Asked Questions and Answers for them and list of well known problems with links to related discussions.
Q:OpenCV still uses Lena image. Why?
A: The Lena image is widely used for accuracy testing, performance testing and a lot of algorithms illustration. OpenCV team respects the wishes of Lena Forsén and decides will no longer accept new pull requests and documentation pages with Lena image. However complete image removal from will break performance comparison (some algorithms are data dependent) and requires a lot of regression data re-generation as soon as documentation illustrations. OpenCV team agreed not to decline contributions that do not bring extra value rather than just the image replacement in the existing code.
Q:OpenCV has very powerful testing framework, but it's not a part of distribution. Why?
A: "ts" is internal module, it is not designed for using it externally - so it was removed from regular public modules list.You may consideropencv_contrib approach of developing OpenCV external modules. (-DOPENCV_EXTRA_MODULES_PATH=path1\;path2 - note on backslash before;, required by "bash").
Discussion:#8408
Q:OpenCV build fails with internal compiler error (a.k.a ICE) or segmentation fault on my ARM board. What can I do?
A: OpenCV team does not work on such kind of bug reports and the best solution for it is to file bugs to compiler team. However there are several popular solutions to fix the problem:
- Reduce amount of build jobs in make and even remove
-joption frommakecommand line. Each build job is dedicated compiler process that consumes RAM. Serial build without-jconsumes minimal amount of RAM. - Add swap space in your OS. Relates to previous one.
- Use cross compilation approach:link
- Update compiler.
Q:My build failed at downloading third-party resources, such as ADE, IPP and so on. What should I do?
A: Ensure you have Internet connection, especially good connection to github.com. Most of the third-party resources are kept on GitHub and some of them will be downloaded for default OpenCV build. For users in China who may have connection problem with GitHub, they can use our official mirror for downloading third-party resources:
# opencv cloned from github, need to use '-DOPENCV_DOWNLOAD_MIRROR_ID=gitcode' to specify the source to gitcodegit clone https://github.com/opencv/opencv.gitcd opencvmkdir build&&cd buildcmake -DOPENCV_DOWNLOAD_MIRROR_ID=gitcode ..# opencv cloned from gitcode, third-party resources will be downloaded automatically from gitcodegit clone https://gitcode.net/opencv/opencv.gitcd opencvmkdir build&&cd buildcmake ..
Discussion: TBD
Q:What is InputArray and how can I understand the actual input types of parameters?
A: This is the proxy class for passing read-only input arrays into OpenCV functions. The class should not be used in user code, passcv::Mat,cv::UMat,cv::GpuMat orstd::vector<> as function parameter and OpenCV extracts data from it without memory copying. In case if you work on new OpenCV module in Contrib repository or new function for core library you should usecv::_InputArray::getMat() method to construct a matrix header for the array inside function.cv::_InputArray::kind() can be used to distinguish actual input container format, but usually it is not needed.
Documentation:https://docs.opencv.org/master/d4/d32/classcv_1_1__InputArray.html
Q:What is type of empty Mat, UMat, GpuMat?
A: Type of empty matrix is undefined. Some OpenCV functions clean output arrays with OutputArray::release(), and it makes the output array type undefined too. The only exceptions are:copyTo andconvertTo methods of Mat, UMat, and GpuMat. The mentioned methods force output type even for empty matrix.
TBD
Q:Why does OpenCV not provide functions withwchar_t,wstring? What about non-Latin symbols in file names?
A: OpenCV team decided to stay conservative and do not introduce new API calls withwchar_t,wstring and other string types By the following reasons:
- Most of image decoding and encoding libraries use standard
fopencall to open files and extrawchar_tsupport requires domain libraries modification. - Modern Linux, Mac OS and latest Windows releases support UTF-8 encoding that allows to use
std::stringas container to pass it to OpenCV functions. - Popular FS, including solutions on Linux does not use
wchar_tnatively and the overloads are not cross platform.
There are 2 alternatives to usewchar_t strings with OpenCV (see discussion section for code snippets and solutions):
Convert
wchar_tstrings to UTF-8 and pass UTF-8 string ascv::imread,cv::imwrite, etc parameter. UTF-8 string is handled by systemfopencall and its behavior depends on OS support and locale. Seembstowcsin C++ standard for more details.OpenCV provides
cv::imdecodeandcv::imencodefunctions that allow to decode and encode image using memory buffer as input and output. The solution decouples file IO and image decoding and allows to manage path strings, locales, etc in user code.
Q:VideoCapture cannot open my file/camera or does it in wrong way. How can I resolve the issue?
A:cv::VideoCapture uses different backends for different cameras, files and platforms. There are several things to check and try with OpenCV:
- OpenCV build options and available backends with
cv::getBuildInformation()(cv2.getBuildInformation()in Python). Seedocumentation for details. - Run your application with
OPENCV_VIDEOIO_DEBUG=1option to enable extra logging inside the library. It helps to identify the backend used in run time and configuration details. - Force OpenCV to use particular backend with the second parameter in constructor. Seedocumentation for details.
Discussion: TBD
Q:Which is more efficient, usecontourArea() or count number of ROI non-zero pixels?
A:cv::contourArea() uses Green formula to compute the area, therefore its complexity isO(contour_number_of_vertices). Counting non-zero pixels in the ROI isO(roi_width*roi_height) algorithm, i.e. much slower. Note, however, that because of finite, and quite low, resolution of the raster grid, the two algorithms will give noticeably different results. For large and square-like contours the error will be minimal. For small and/or oblong contours the error can be quite large.
Links:Green's Theorem
Q:Cannot read frozen object detection.pb with OpenCV DNN API after it was trained with TF Object Detection API. What is the reason?
A: TF Object Detection API provides opportunities for detection model training. There are scripts for TF2, TF1.5 training and further model export, namelymodel_main_tf2.py andexporter_main_v2.py,model_main.py andexport_inference_graph.py. Afterexporter_main_v2.py execution the model, checkpoints and variables will be saved in the specified directory. Observing this model after freezing, you will findStatefulPartitionedCall/... nodes. It indicates TF Eager Mode, which is not supported in OpenCV.
One of the options is using TF1.5 scripts:model_main.py andexport_inference_graph.py.
Discussion:#19257
Q:Is there control flow support in OpenCV?
A: OpenCV doesn't support control flow and currently, there is no plan for the near future to implement it.
Error example:onnx_graph_simplifier.cpp:592: error: (-210:Unsupported format or combination of formats) Unsupported data type: BOOL in function 'getMatFromTensor'
The problem appeared during.onnx feeding intocv2.dnn.readNetFromONNX(...).
Discussion:#19366,#19977
Q:Why OpenCV ONNX parser is not able to parse onnx file that containstorch.nn.functional.interpolate resize function and how to solve that?
A: When flagrecompute_scale_factor=True oftorch.nn.functional.interpolate function, due to internal implementation of interpolate function in torch library, currently some nodes are not be handled by OpenCV properly. Solution to this problem is to follow simply the graph that containstorch.nn.functional.interpolate. It can be does as follows:
fromonnxsimimportsimplify....onnx_model=onnx.load(full_model_path)onnx.checker.check_model(onnx_model)############################################## =======> Simplify ONNX graph <======== ##onnx_model,check=simplify(onnx_model)onnx.save(onnx_model,full_model_path)############################################
See thisthread for me details
Q:Why I get build error "This file was generated by an older version of protoc"?A: OpenCV DNN supports Caffe, TensorFlow and ONNX models that are built on top of Prtobuf. OpenCV repository contains own instance of Protobuf, .proto files for all formats and generated C/C++ code for .proto files. Generated code is tightly coupled with the Protobuf version you use. The error means that you build OpenCV with some other version of Protobuf library than the code generated from .proto files. It means that you use external Protobuf, or there are more than one Protobuf instance in your project. OpenCV has several CMake options to handle the issue:-DBUILD_PROTOBUF=OFF to use external Protobuf version and-DPROTOBUF_UPDATE_FILES=ON to regenerate code from .proto files with your protoc.
Q:I call OpenCV function as it's done in C++ or stated in documentation, but get some strange data type or buffer size exception. How to debug it?
A: OpenCV Bindings for Python use Numpy Array as base container instead or wrappingcv::Mat to Python. Data conversion is done on-the-go in C++ during function call. Some conversions could be buggy or counterintuitive. OpenCV provides functioncv.utils.dumpInputArray() that returns details of C++ representation of Python arrays that can help.
Documentation:#16807#19091,#17456
Q:May I use inheritance with OpenCV classes in Python?
A: No, OpenCV classes are C++ classes wrapped to Python. Inheritance is not supported right now and may lead to segmentation fails and other undefined behavior.
Q:I tried to build the OpenCV-Python from source on Windows with Python 3.9, but afterimport cv2 got an error:ImportError: DLL load failed while importing cv2: The specified module could not be found.
A: Python 3.9 has changed the way libraries are loaded. You can downgrade your Python's version to 3.8 or setup additional environment variables as described at#20206.
© Copyright 2019-2025, OpenCV team