Change language

Python | Angle detection by Shi-Tomazi angle detection method using OpenCV

What is an angle?
An angle can be interpreted as the connection of two edges (where the edge is a sudden change in the brightness of the image).

Shi-Tomazi Corner Discovery —

Discovery of Shi-Tomasi Corner was published by J.Shi and C.Tomasi in their article " Good Tracking Performance ". The basic intuition here is that corners can be detected by looking for significant changes in all directions.

We look at a small window in the image, then scan the entire image for corners.

Offset of this small window in any direction will cause a significant change in appearance if that particular window ends up in a corner. 

Flat regions will not change in any direction. 

If there is an edge, then there will be no significant changes along the direction of the edge. 

Mathematical overview —

For window (W) located at point (X, Y) with pixel intensity I (X, Y), the formula for determining the Shi-Tomasi angle is —

 f ( X, Y) = Σ (I (X  k , Y  k ) - I (X  k  + ΔX, Y  k  + ΔY))  2  where (X  k , Y  k ) ϵ W 

By formula:
If we scan an image with a window, as if we were working with the kernel, and we notice that there is an area in which significant changes are taking place, no matter which direction we are actually in scan, then we have a good intuition that there is probably an angle there.

Calculating f (X, Y) will be very slow. Therefore, we use the Taylor extension to simplify the scoring function, R.

 R = min (λ  1 , λ  2 ) where λ  1 , λ  2  are the eigenvalues ​​of the resulting matrix 

Using the function goodFeaturesToTrack ()

Syntax: cv2.goodFeaturesToTrack (gray_img, maxc, Q, minD)

Parameters:
gray_img - Grayscale image with integral values ​​
maxc - Maximum number of corners we want (give negative value to get all the corners)
Q - Quality level parameter (preferred value = 0.01)
maxD - Maximum distance (preferred value = 10)

Below is the Python implementation of the Shi-Tomazi angle definition:

# Python program to illustrate
# corner detection
# Method detecting Shi-Tomazi

 
# organizing imports

import cv2

import numpy as np

import matplotlib.pyplot as plt

% matplotlib inline

 
# path to the specified input image and
# the image is loaded using the imread command

img = cv2.imread ( ’chess.png’ )

 
# convert image to grayscale

gray_img = cv2.cvtColor (img, cv2.COLOR_BGR2GRAY)

 
# Shi-Tomazi corner detection function
# We only find the 100 best corners here
# You can change the number to get the desired result.

corners = cv2.goodFeaturesToTrack (gray_img, 100 , 0.01 , 10 )

 
# convert angle values ​​to c white number
# So we can draw circles on them

corners = np.int0 (corners)

  
# draw circles in red on all corners

for i in corners:

  x, y = i.ravel ()

cv2.circle (img, (x, y), 3 , ( 255 , 0 , 0 ), - 1 )

 
# resulting image
plt.imshow (img)

 
# Deselect any associated memory usage

if cv2.waitKey ( 0 ) & amp;  0xff = = 27

cv2.destroyAllWindows ()

Login:

Output:

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically