Questions tagged [opencv]

OpenCV (Open Source Computer Vision) is a library for real time computer vision. When using this tag, please add a language specific tag (python, c++, ...), if relevant.

OpenCV is a code library for Computer Vision related applications, spanning from many very basic tasks (capture and pre-processing of image data) to high-level algorithms (feature extraction, motion tracking, machine learning).

It is free software. Versions from 4.5.0 are licensed under the Apache 2 license, versions before that under the BSD 3-clause license. OpenCV provides a rich API in C++, Python, and Java. Third party wrappers are available. The library is platform-independent and often used for real-time image processing and computer vision (e.g. tracking in videos). It supports Windows, Linux, and OS X as well as Android (native and Java) and iOS.

OpenCV was officially launched by Intel in 1999. Version 2.0 (2009) was an important landmark as it introduced the new, comprehensive C++ interface, which since then is also to be used internally in the library. Since this release, OpenCV saw a strong acceleration of development in improving the library and adding new features. Version 3.0, released in 2015, deprecated the C API and emphasized object-oriented design for increased modularity and intuitive interface. More information may be found in Wikipedia.

Latest stable versions:

Homepage: https://opencv.org

Documentation: https://docs.opencv.org

Tutorials including source code:


Books

Note that this list is likely outdated and not vetted for quality. A book or course on computer vision in general, along with the official documentation of OpenCV, will give a better understanding of the matter and the library.

72729 questions
81
votes
7 answers

Converting an OpenCV Image to Black and White

How do you convert a grayscale OpenCV image to black and white? I see a similar question has already been asked, but I'm using OpenCV 2.3, and the proposed solution no longer seems to work. I'm trying to convert a greyscale image to black and white,…
Cerin
  • 60,957
  • 96
  • 316
  • 522
81
votes
9 answers

PyLint not recognizing cv2 members

I am running pylint on an opencv project and I am getting many pylint errors in VS code about members not being present. Example code: import cv2 cv2.imshow(....) Errors obtained: However , the code runs correctly without any errors. Versions :…
Kitwradr
  • 1,986
  • 3
  • 18
  • 32
80
votes
13 answers

Writing an mp4 video using python opencv

I want to capture video from a webcam and save it to an mp4 file using opencv. I found example code on stackoverflow (below) that works great. The only hitch is that I'm trying to save it as mp4, not avi. Part of what I don't get is that the 'XVID'…
Gadzooks34
  • 1,718
  • 2
  • 20
  • 29
80
votes
5 answers

Clone an image in cv2 Python

I'm new to OpenCV. What is the Python function which act the same as cv::clone() in C++? I just try to get a rect by rectImg = img[10:20, 10:20] but when I draw a line on it, I find the line appear both on img and the rectImage, so, how can I…
tintin
  • 1,459
  • 1
  • 10
  • 27
79
votes
7 answers

How do I resolve "Please make sure that the file is accessible and that it is a valid assembly or COM component"?

I am building a project with OpenCV in C#. It requires a dll file called cvextern.dll. but, when adding this file as a reference, this message appears :- a reference "cvextern.dll" can't be added, Please make sure that the file is accessible and…
Omar Osama
  • 1,401
  • 3
  • 19
  • 29
79
votes
27 answers

DLL load failed error when importing cv2

I have installed opencv on my windows machine using python 3.6 without any issues, using: pip install opencv-python but when I try to import cv2 I get the following error ImportError: DLL load failed: The specified module could not be found. I…
Cameron Wasilewsky
  • 962
  • 2
  • 10
  • 12
79
votes
12 answers

Rotate image and crop out black borders

My application: I am trying to rotate an image (using OpenCV and Python) At the moment I have developed the below code which rotates an input image, padding it with black borders, giving me A. What I want is B - the largest possible area crop…
aaronsnoswell
  • 6,051
  • 5
  • 47
  • 69
78
votes
4 answers

Detect and visualize differences between two images with OpenCV Python

I have two images and would like to make it obvious where the differences are. I want to add color to the two images such that a user can clearly spot all the differences within a second or two. For example, here are two images with a few…
PlsWork
  • 1,958
  • 1
  • 19
  • 31
78
votes
7 answers

How to convert a python numpy array to an RGB image with Opencv 2.4?

I have searched for similar questions, but haven't found anything helpful as most solutions use older versions of OpenCV. I have a 3D numpy array, and I would like to display and/or save it as a BGR image using OpenCV (cv2). As a short example,…
Gillespie
  • 915
  • 1
  • 6
  • 6
78
votes
13 answers

Package opencv was not found in the pkg-config search path

I have installed OpenCV using the instructions in https://help.ubuntu.com/community/OpenCV $ sudo su $ sudo apt-get install build-essential $ sudo apt-get install libavformat-dev $ sudo apt-get install ffmpeg $ sudo apt-get install libcv2.3…
aliep
  • 1,702
  • 2
  • 21
  • 33
78
votes
3 answers

How to define the markers for Watershed in OpenCV?

I'm writing for Android with OpenCV. I'm segmenting an image similar to below using marker-controlled watershed, without the user manually marking the image. I'm planning to use the regional maxima as markers. minMaxLoc() would give me the value,…
Tru
  • 1,467
  • 5
  • 18
  • 27
76
votes
4 answers

How to use OpenCV's connectedComponentsWithStats in Python?

I am looking for an example of how to use OpenCV's connectedComponentsWithStats() function in Python. Note this is only available with OpenCV 3 or newer. The official documentation only shows the API for C++, even though the function exists when…
Zack Knopp
  • 2,765
  • 2
  • 13
  • 14
76
votes
3 answers

Why OpenCV Using BGR Colour Space Instead of RGB

Why OpenCV using BGR colour space instead of RGB. We all know that RGB is the convenient colour model for most of the computer graphics and also the human visual system works in a way that is similar to a RGB colour space. Is there any reason behind…
Haris
  • 13,645
  • 12
  • 90
  • 121
76
votes
2 answers

Computing x,y coordinate (3D) from image point

I have a task to locate an object in 3D coordinate system. Since I have to get almost exact X and Y coordinate, I decided to track one color marker with known Z coordinate that will be placed on the top of the moving object, like the orange ball in…
Banana
  • 1,276
  • 2
  • 16
  • 19
75
votes
8 answers

.Net (dotNet) wrappers for OpenCV?

I've seen there are a few of them. opencvdotnet, SharperCV, EmguCV, One on Code Project. Does anyone have any experience with any of these? I played around with the one on Code Project for a bit, but as soon as I tried to do anything complicated…
Kris Erickson
  • 33,454
  • 26
  • 120
  • 175