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.

Filter by
Sorted by
Tagged with
1910 votes
23 answers
241k views

Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition

One of the most interesting projects I've worked on in the past couple of years was a project about image processing. The goal was to develop a system to be able to recognize Coca-Cola 'cans' (note ...
Charles Menguy's user avatar
448 votes
26 answers
2.1m views

Cannot find module cv2 when using OpenCV [duplicate]

I have installed OpenCV on the Occidentalis operating system (a variant of Raspbian) on a Raspberry Pi, using this script by jayrambhia. It installed version 2.4.5. When I try import cv2 in a Python ...
user2971844's user avatar
  • 4,513
429 votes
3 answers
271k views

Simple Digit Recognition OCR in OpenCV-Python

I am trying to implement a "Digit Recognition OCR" in OpenCV-Python (cv2). It is just for learning purposes. I would like to learn both KNearest and SVM features in OpenCV. I have 100 samples (i.e. ...
Abid Rahman K's user avatar
411 votes
12 answers
1.0m views

How to crop an image in OpenCV using Python

How can I crop images, like I've done before in PIL, using OpenCV. Working example on PIL im = Image.open('0.png').convert('L') im = im.crop((1, 1, 98, 33)) im.save('_0.png') But how I can do it ...
Nolik's user avatar
  • 4,415
395 votes
10 answers
26k views

How to detect a Christmas Tree?

Which image processing techniques could be used to implement an application that detects the Christmas trees displayed in the following images? I'm searching for solutions that are going to work ...
karlphillip's user avatar
  • 92.8k
314 votes
44 answers
998k views

How do I install Python OpenCV through Conda?

I'm trying to install OpenCV for Python through Anaconda, but I can't seem to figure this out. I tried conda install opencv conda install cv2 I also tried searching conda search cv No cigar. I ...
Chet's user avatar
  • 19k
261 votes
24 answers
867k views

How do I install opencv using pip?

I need to install cv2 for a script that has been written for me. I tried pip install cv2 and pip install open_cv and got the same problem - a warning message from dist.py and complains about zlib ...
Ian Boag's user avatar
  • 2,782
256 votes
14 answers
604k views

Python - Extracting and Saving Video Frames

So I've followed this tutorial but it doesn't seem to do anything. Simply nothing. It waits a few seconds and closes the program. What is wrong with this code? import cv2 vidcap = cv2.VideoCapture('...
Rontron's user avatar
  • 4,133
238 votes
35 answers
636k views

ImportError: numpy.core.multiarray failed to import

I'm trying to run this program import cv2 import time cv.NamedWindow("camera", 1) capture = cv.CaptureFromCAM(0) while True: img = cv.QueryFrame(capture) cv.ShowImage("camera&...
user avatar
232 votes
9 answers
173k views

Simple and fast method to compare images for similarity

I need a simple and fast way to compare two images for similarity. I.e. I want to get a high value if they contain exactly the same thing but may have some slightly different background and may be ...
Albert's user avatar
  • 66.8k
230 votes
12 answers
192k views

Is there a way to detect if an image is blurry? [closed]

I was wondering if there is a way to determine if an image is blurry or not by analyzing the image data.
Sam's user avatar
  • 4,827
223 votes
5 answers
640k views

How to resize an image with OpenCV2.0 and Python2.6

I want to use OpenCV2.0 and Python2.6 to show resized images. I used and adopted this example but unfortunately, this code is for OpenCV2.1 and does not seem to be working on 2.0. Here my code: import ...
Bastian's user avatar
  • 9,675
217 votes
6 answers
46k views

How to remove convexity defects in a Sudoku square?

I was doing a fun project: Solving a Sudoku from an input image using OpenCV (as in Google goggles etc). And I have completed the task, but at the end I found a little problem for which I came here. ...
Abid Rahman K's user avatar
205 votes
6 answers
264k views

Checking images for similarity with OpenCV

Does OpenCV support the comparison of two images, returning some value (maybe a percentage) that indicates how similar these images are? E.g. 100% would be returned if the same image was passed twice, ...
Boris's user avatar
  • 8,773
202 votes
11 answers
902k views

How to display an image

I tried to use IPython.display with the following code: from IPython.display import display, Image display(Image(filename='MyImage.png')) I also tried to use matplotlib with the following code: ...
FiReTiTi's user avatar
  • 5,787
193 votes
6 answers
133k views

OpenCV C++/Obj-C: Detecting a sheet of paper / Square Detection

I successfully implemented the OpenCV square-detection example in my test application, but now need to filter the output, because it's quite messy - or is my code wrong? I'm interested in the four ...
dom's user avatar
  • 12k
181 votes
2 answers
14k views

OpenCV – Depth map from Uncalibrated Stereo System

I'm trying to get a depth map with an uncalibrated method. I can obtain the fundamental matrix by finding correspondent points with SIFT and then using cv2.findFundamentalMat. I then use cv2....
user3601754's user avatar
  • 3,832
173 votes
20 answers
341k views

cv2.imshow command doesn't work properly in opencv-python

I'm using opencv 2.4.2, python 2.7 The following simple code created a window of the correct name, but its content is just blank and doesn't show the image: import cv2 img=cv2.imread('C:/Python27/...
top.eng's user avatar
  • 1,848
171 votes
5 answers
281k views

Convert image from PIL to openCV format

I'm trying to convert image from PIL to OpenCV format. I'm using OpenCV 2.4.3. here is what I've attempted till now. >>> from PIL import Image >>> import cv2 as cv >>> pimg =...
md1hunox's user avatar
  • 3,915
169 votes
10 answers
132k views

Extracting text OpenCV

I am trying to find the bounding boxes of text in an image and am currently using this approach: // calculate the local variances of the grayscale image Mat t_mean, t_mean_2; Mat grayF; outImg_gray....
Clip's user avatar
  • 3,068
165 votes
14 answers
237k views

OpenCV in Android Studio

I want to use OpenCV library in my app with Android Studio. I followed instructions found here but I get error Configuration with name 'default' not found What can be wrong? I use Android Studio ...
Bartosz Bialecki's user avatar
163 votes
15 answers
483k views

how to convert an RGB image to numpy array?

I have an RGB image. I want to convert it to numpy array. I did the following im = cv.LoadImage("abc.tiff") a = numpy.asarray(im) It creates an array with no shape. I assume it is a iplimage object.
Shan's user avatar
  • 19k
161 votes
9 answers
281k views

How can I sharpen an image in OpenCV?

How can I sharpen an image using OpenCV? There are many ways of smoothing or blurring but none that I could see of sharpening.
AruniRC's user avatar
  • 5,120
157 votes
6 answers
221k views

How to find out what type of a Mat object is with Mat::type() in OpenCV?

I am kind of confused with type() method of Mat object in OpenCV.If I have following lines: mat = imread("C:\someimage.jpg"); type = mat.type(); and type = 16, how do I find out what type ...
Tae-Sung Shin's user avatar
157 votes
26 answers
337k views

error: (-215) !empty() in function detectMultiScale

I'm trying to learn cv2 in python 2.7, but when I run my code, in the specific part of it: face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2....
arthurckl's user avatar
  • 5,351
157 votes
5 answers
322k views

Size of Matrix OpenCV

I know this might be very rudimentary, but I am new to OpenCV. Could you please tell me how to obtain the size of a matrix in OpenCV?. I googled and I am still searching, but if any of you know the ...
Lakshmi Narayanan's user avatar
153 votes
21 answers
337k views

Pycharm/Python OpenCV and CV2 install error [duplicate]

I've been trying to install both OpenCV and cv2 from both Pycharm and from the terminal as suggested using: pip install --user opencv pip install --user cv2 but I'm getting the following error for ...
Sibi's user avatar
  • 2,361
151 votes
9 answers
172k views

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

When trying to import OpenCV, using import cv2 I get the following error: /usr/local/lib/python2.7/dist-packages/cv2/__init__.py in <module>() 7 8 # make IDE's (PyCharm) ...
Dmitry Rastorguev's user avatar
146 votes
3 answers
407k views

Python OpenCV2 (cv2) wrapper to get image size?

How to get the size of an image in cv2 wrapper in Python OpenCV (numpy). Is there a correct way to do that other than numpy.shape(). How can I get it in these format dimensions: (width, height) list?
xercool's user avatar
  • 4,439
130 votes
7 answers
143k views

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, ...
gabbar0x's user avatar
  • 4,156
130 votes
23 answers
611k views

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 ...
Charklewis's user avatar
  • 5,091
130 votes
24 answers
497k views

ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL's are there

I have a situation very much like the one at Error "ImportError: DLL load failed: %1 is not a valid Win32 application", but the answer there isn't working for me. My Python code says: import ...
LarsH's user avatar
  • 27.8k
129 votes
13 answers
343k views

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, ...
Zynk's user avatar
  • 2,955
124 votes
21 answers
259k views

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 ...
Isaiah Nields's user avatar
120 votes
4 answers
296k views

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's user avatar
  • 12.6k
118 votes
10 answers
336k views

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 ...
Student FourK's user avatar
116 votes
2 answers
85k views

Should I use libc++ or libstdc++? [closed]

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's user avatar
  • 3,760
114 votes
5 answers
151k views

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's user avatar
  • 1,181
114 votes
5 answers
430k views

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 ...
user391339's user avatar
  • 8,595
113 votes
8 answers
63k views

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 > ...
Nathan Keller's user avatar
112 votes
9 answers
297k views

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 ...
Chandra Shaker Balure's user avatar
110 votes
7 answers
316k views

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 ...
Mansueli's user avatar
  • 6,683
110 votes
4 answers
137k views

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

I have a 300x200 image in a Matrix src. I am applying the following operation on the image. for(int i=0;i<src.rows;i++){ for(int j=0;j<src.cols;j++){ line( src, Point(i,j),Point(i,j), ...
user3747190's user avatar
  • 1,687
109 votes
6 answers
72k views

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 ...
Basj's user avatar
  • 44.1k
107 votes
5 answers
315k views

Setting Camera Parameters in OpenCV/Python

I am using OpenCV (2.4) and Python (2.7.3) with a USB camera from Thorlabs (DC1545M). I am doing some image analysis on a video stream and I would like to be able to change some of the camera ...
Mike's user avatar
  • 1,777
104 votes
5 answers
252k views

ConvergenceWarning: Liblinear failed to converge, increase the number of iterations

Running the code of linear binary pattern for Adrian. This program runs but gives the following warning: C:\Python27\lib\site-packages\sklearn\svm\base.py:922: ConvergenceWarning: Liblinear failed ...
Fahad Mairaj's user avatar
  • 1,061
104 votes
6 answers
202k views

OpenCV imshow doesn't need convert from BGR to RGB

As I'm lead to believe, OpenCV reads images in BGR colorspace ordering and we usually have to convert it back to RGB like this: img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) But when I try to simply ...
Cypher's user avatar
  • 2,497
103 votes
12 answers
182k views

What's 0xFF for in cv2.waitKey(1)?

I'm trying understand what 0xFF does under the hood in the following code snippet: if cv2.waitKey(0) & 0xFF == ord('q'): break Any ideas?
Dora's user avatar
  • 1,183
103 votes
9 answers
202k views

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's user avatar
  • 48.3k
102 votes
12 answers
219k views

OpenCV Python rotate image by X degrees around specific point

I'm having a hard time finding examples for rotating an image around a specific point by a specific (often very small) angle in Python using OpenCV. This is what I have so far, but it produces a very ...
Mike's user avatar
  • 1,017

1
2 3 4 5
1471