OpenCV Python cv2.perspectiveTransform

This implementation really needs to be changed in a future version. From the OpenCV docs for perspectiveTransform(): src – input two-channel (…) floating-point array Slant emphasis added by me. So we see from here that A is just a single-channel matrix, that is, two-dimensional. One row, two cols. You instead need a two-channel image, i.e., a three-dimensional matrix where the length of the … Read more

Why do we convert from RGB to HSV

According to http://en.wikipedia.org/wiki/HSL_and_HSV#Use_in_image_analysis : Because the R, G, and B components of an object’s color in a digital image are all correlated with the amount of light hitting the object, and therefore with each other, image descriptions in terms of those components make object discrimination difficult. Descriptions in terms of hue/lightness/chroma or hue/lightness/saturation are often more relevant. … Read more

explain arguments meaning in res = cv2.bitwise_and(img,img,mask = mask)

The basic concept behind this is the value of color black ,it’s value is 0 in OPEN_CV.So black + anycolor= anycolor because value of black is 0. Now suppose we have two images one is named img1 and other is img2. img2 contains a logo which we want to place on the img1. We create threshold and then the mask and mask_inv of img2,and … Read more

How to detect simple geometric shapes using OpenCV

If you have only these regular shapes, there is a simple procedure as follows : Find Contours in the image ( image should be binary as given in your question) Approximate each contour using approxPolyDP function. First, check number of elements in the approximated contours of all the shapes. It is to recognize the shape. For eg, … Read more

Difference in output with waitKey(0) and waitKey(1)

From the doc: 1.waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). 2.waitKey(1) will display a frame for 1 ms, after which display will be automatically closed. Since the OS has a minimum time between switching threads, the function will not wait exactly 1 ms, it will wait at least 1 ms, depending on what else is running … Read more