SoFunction
Updated on 2024-11-20

Python Implementation of Polar Coordinate Transformation in OpenCV

In high school, we learned about the right-angle coordinate system, also called the Cartesian coordinate system, which is orthogonal, but we also learned about the polar coordinate system, which is better suited for cannon firing situations. The polar coordinate system is defined as follows:

Take a fixed point O in the plane, call it the pole, draw a ray Ox, call it the polar axis, and then choose a unit of length and the positive direction of the angle (usually take the counterclockwise direction). For any point M in the plane, use ρ to represent the length of the line segment OM, θ to represent the angle from Ox to OM, ρ is called the polar diameter of the point M, θ is called the polar angle of the point M, the sequential number of pairs (ρ,θ) is called the polar coordinates of the point M, so that the establishment of the coordinate system is called the polar coordinate system.

Polar coordinates are conveniently applied to the radar, because the radar is constantly rotating, and the wave reflected back calculates the distance, and then with the angle of rotation, it constitutes a two-dimensional map of the coordinates. There are also people who use such a radar chart to represent the sales performance of the formula, so that it is convenient to compare the results of different people, you can see the gap between each person. The following is the use of python and matplotlib to realize such a plot, so that we have a clear understanding of the polar coordinates, in order to later unfold the transformation from right-angle coordinates to polar coordinates to learn, this example code is as follows:

#python 3.7.4,opencv4.1
#Cai Junsheng /caimouse/article/details/51749579
#
import  as plt
import numpy as np
 
['-serif']=['SimHei'] # Used to display Chinese labels properly
['axes.unicode_minus']=False # Used to display the negative sign normally
 
employee = ["Zhang San", "Li Si.", "Cai Da", "Pong II.", "Lin 5"]
actual = [45, 53, 55, 61, 57, 45]
expected = [50, 55, 60, 65, 55, 50]
 
# Setting the graph size and display in polar coordinates
(figsize=(5, 5))
(polar=True)
 
# Angular coordinate generation
theta = (0, 2 * , len(actual))
 
# Setting the markers in polar coordinates
lines, labels = (range(0, 360, int(360/len(employee))), (employee))
 
# Display sales values in polar coordinates
(theta, actual)
(theta, actual, 'b', alpha=0.1)
 
# Polarized display of desired sales values
(theta, expected)
 
# Add labels and titles
(labels=('Actual value', 'Expectations'), loc=1)
("Actual versus expected")
 
# Display point to screen
()

The output is as follows:

summarize

The above is a small introduction to the Python in OpenCV to realize the polar coordinate transformation function, I hope to help you, if you have any questions please leave me a message, I will reply to you in time. I would also like to thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and please note the source, thank you!