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
125
votes
23 answers

imread returns None, violating assertion !_src.empty() in function 'cvtColor' error

I am trying to do a basic colour conversion in python however I can't seem to get past the below error. I have re-installed python, opencv and tried on both python 3.4.3 (latest) and python 2.7 (which is on my Mac). I installed opencv using python's…
Charklewis
  • 4,427
  • 4
  • 31
  • 69
123
votes
7 answers

OpenCV giving wrong color to colored images on loading

I'm loading in a color image in Python OpenCV and plotting the same. However, the image I get has it's colors all mixed up. Here is the code: import cv2 import numpy as np from numpy import array, arange, uint8 from matplotlib import pyplot as…
gabbar0x
  • 4,046
  • 5
  • 31
  • 51
121
votes
21 answers

RuntimeError: module compiled against API version a but this version of numpy is 9

Code: import numpy as np import cv Console: >>> runfile('/Users/isaiahnields/.spyder2/temp.py', wdir='/Users/isaiahnields/.spyder2') RuntimeError: module compiled against API version a but this version of numpy is 9 Traceback (most recent call…
Isaiah Nields
  • 1,221
  • 2
  • 8
  • 4
120
votes
13 answers

OpenCV & Python - Image too big to display

I have an image that is 6400 × 3200, while my screen is 1280 x 800. Therefore, the image needs to be resized for display only. I am using Python and OpenCV 2.4.9. According to OpenCV Documentation, If you need to show an image that is bigger than…
Zynk
  • 2,767
  • 3
  • 12
  • 11
116
votes
2 answers

Should I use libc++ or libstdc++?

I am developing command line interface executables for both osx and linux using c/c++. The project will link against opencv. Should I use libc++ or libstdc++?
MobileDev
  • 3,750
  • 4
  • 32
  • 35
115
votes
4 answers

OpenCV: draw a rectangle around a region

How can I use OpenCV in Python to draw rectangles around some regions within an image for object detection purposes?
user961627
  • 12,379
  • 42
  • 136
  • 210
113
votes
8 answers

Algorithm to detect corners of paper sheet in photo

What is the best way to detect the corners of an invoice/receipt/sheet-of-paper in a photo? This is to be used for subsequent perspective correction, before OCR. My current approach has been: RGB > Gray > Canny Edge Detection with thresholding >…
113
votes
10 answers

Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)

I have an image of a coffee can with an orange lid position of which I want to find. Here is it . gcolor2 utility shows HSV at the center of the lid to be (22, 59, 100). The question is how to choose the limits of the color then? I tried min = (18,…
Student FourK
  • 1,323
  • 2
  • 10
  • 6
111
votes
5 answers

How to know total number of Frame in a file with cv2 in python

How to know total number of Frame in a file ( .avi) through Python using open cv module. If possible what all the information (resolution, fps,duration,etc) we can get of a video file through this.
Niraj
  • 1,151
  • 2
  • 8
  • 9
111
votes
5 answers

How does one convert a grayscale image to RGB in OpenCV (Python)?

I'm learning image processing using OpenCV for a realtime application. I did some thresholding on an image and want to label the contours in green, but they aren't showing up in green because my image is in black and white. Early in the program I…
user391339
  • 8,355
  • 13
  • 58
  • 71
107
votes
7 answers

inverting image in Python with OpenCV

I want to load a color image, convert it to grayscale, and then invert the data in the file. What I need: to iterate over the array in OpenCV and change every single value with this formula (it might be wrong but it seems reasonable for me):…
Mansueli
  • 6,223
  • 8
  • 33
  • 57
107
votes
9 answers

How to write text on a image in windows using python opencv2

I want to put some text on an Image. I am writing the code as: cv2.putText(image,"Hello World!!!", (x,y), cv2.CV_FONT_HERSHEY_SIMPLEX, 2, 255) It gives ERROR, saying 'module' object has no attribute 'CV_FONT_HERSHEY_SIMPLEX' Query Can't I use the…
Chandra Shaker Balure
  • 1,181
  • 2
  • 7
  • 5
105
votes
4 answers

OpenCV Point(x,y) represent (column,row) or (row,column)

I have a 300x200 image in a Matrix src. I am doing the following operation on the image. for(int i=0;i
user3747190
  • 1,627
  • 3
  • 20
  • 28
103
votes
6 answers

Automatic contrast and brightness adjustment of a color photo of a sheet of paper with OpenCV

When photographing a sheet of paper (e.g. with phone camera), I get the following result (left image) (jpg download here). The desired result (processed manually with an image editing software) is on the right: I would like to process the original…
Basj
  • 41,386
  • 99
  • 383
  • 673
103
votes
9 answers

What does OpenCV's cvWaitKey( ) function do?

What happens during the execution of cvWaitKey()? What are some typical use cases? I saw it in OpenCV reference but the documentation isn't clear on its exact purpose.
Simplicity
  • 47,404
  • 98
  • 256
  • 385