how to extracts icons positions from desktop screenshot in python - python-3.x

I want to extract coordinates of theses icon ,How can I do this using python
Any help will be appreciated enter image description here
Thank you

Does it help you?
def get_pos_x(col):
return (col - 1) * 51 + 1
def get_pos_y(row):
return 4 + (row - 1) * 56 + (row - 1) * 11 + 1
icon = (51, 56) # width * height
col = 2
row = 2
print(get_pos_x(col))
print(get_pos_y(row))
Each icon needs on your screen 51 pixels in width and 56 pixels in height. In addition, consider the distance to the first row of 4 pixels and between the rows of 11 pixels. I've added a pixel to x and y so that you can get to the next icon.

Related

Creating a 2D grid of coordinates relative to a set heading

I am trying to create a grid of coordinates that also takes into account a heading as well.
I am able to make the grid but I am not sure how to rotate the grid based on a heading I pass in.
For example: I want to create a 2D grid starting at 0,0 that outputs 4 coordinate positions. This has 2 columns and 2 rows and has a heading of 45 degrees in radians (0.785398)
This is what I am currently seeing:
Current Result
This is what I am roughly hoping to see:
Intended result
Code:
import math
startX = 0.0
startY = 0.0
heading = 0.785398
columns = 2
column = 0
row = 0
rows = 2
total = columns * rows
spacing = 10.0
i = 0
x = 0.0
y = 0.0
while i < total:
i += 1
x = x + (spacing * math.cos(heading)) * column
y = y + (spacing * math.sin(heading)) * row
print(str(x) + "," + str(y))
column += 1
if column >= columns:
row += 1
column = 0
Any help would be greatly appreciated. Thanks!

How to know the location of a point in a rotated grid with equal sized square-shaped cells

Given a grid inclined at an angle θ (theta) with equal sized square-shaped cells with indices 00, 01, 02, ..., 55 (where first digit being x index and second being y index, for instance 00 means a cell at the intersection of row 0 and column 0), and a point p(x,y), how can we know that in which grid cell does the point lie without checking all the cells?
For instance, in the image below point p lies in the cell with index 23.
I found one answer at Checking if a point is inside a rotated rectangle that explains how to determine if a point lies inside a rotated rectangle, but with this approach I need to check all the grid cells.
Perhaps the simplest way - rotate point by the same angle (with negative sign) and check new coordinates in axis-aligned grid
nx = x * cos(theta) - y * sin(theta)
ny = x * sin(theta) + y * cos(theta)
row = (int) (ny / cellsize)
col = (int) (nx / cellsize)

How to calculate the total number of circle coordinates?

If having a centre(xc,yc) and radius(r), how can i calculate total number of coordinates(x,y) in the circle?
I suspect that you are talking about integer points in the circle. Otherwise question is senseless.
In this case you can apply Gauss formula
N = 1 + 4 * r + 4 * sum[i=1..r]{floor(sqrt(r^2-i^2))}
Note that center has integer coordinates too.

Solving a large system of equations using VBA

I'm trying to solved a system of equations that results from estimating a 4th order differential equation. To do this requires creating a large matrix (A), usually 105 x 105, taking the inverse and multiplying by a 105 x 1 matrix (B). To do this, I'm using the linear algebra approach solving Ax = B.
Running the following code:
Dim A(1 To 105, 1 To 105) As Double
Dim B(1 To 105) As Double
Dim i As Integer
' Used to make sure all values of A are initialized to zero
For i = 1 To 105
For j = 1 To 105
A(i, j) = 0
Next
Next
For i = 1 To 105
A(i, i) = EI
A(i, i + 1) = -4 * EI + axial * h ^ 2
A(i, i + 2) = 6 * EI - 2 * axial * h ^ 2 + km(i) * h ^ 4
A(i, i + 3) = -4 * EI + axial * h ^ 2
A(i, i + 4) = EI
B(i) = W * h ^ 4
Next
Dim x(1 To 105) As Variant
x = Application.WorksheetFunction.MMult((Application.WorksheetFunction.MInverse(A)), B)
results in "Run-time error '1004': Unable to get the MInverse property of the WorksheetFunction class"
I've explored this error and it appears that it means I'm passing bad data to the function either text or blank values so I added the two loops at the top to initialize matrix A to 0 however this did nothing. After exploring some more I found some obscure post about a maximum size of matrices being 52 x 52 but wasn't able to find any more information about this.
Yes, there is a limit of 52 x 52, as mentioned in the official documentation.
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.worksheetfunction.minverse.aspx
EDIT
The documentation seems to be wrong. I tested =MINVERSE(A1:DA105) and it works well.
Very likely your matrix contains numbers that generate very large numbers and it fails. I populated my matrix 105 rows with numbers from 1 to 105 and it was failing. Then I put =RAND() in all the cells and it worked.
If the large numbers are the problem, perhaps there are tricks like populating the matrix with the logarithm of the numbers. It's a trick I use in other cases, I don't know if it can be used with a matrix.

In RGB model how many distinct hues are available?

In RGB model, each pixel is defined by 3 bytes, for R,G and B respectively. This gives a total of 224 colors, including 256 tones of grey.
It is very common to represent HSV/HSB/HSL models with floats (not bytes). Most descriptions describe hue as the "angle" in a cone, so it's sensible to treat it as a real number.
But how does this relate to the down-to-earth limit of 224 total colors..? How many distinct hues are available? More over, it seems to me that the number should depend on other parameters - saturation for instance..
Interesting reading: https://web.archive.org/web/20170622125306/http://www.dig.cs.gc.cuny.edu/manuals/Gimp2/Grokking-the-GIMP-v1.0/node52.html
In HSV, the hue is defined as
H = atan2( sqrt(3)*(G-B), 2R-G-B )
(link). In each of the six sectors (R-Y, Y-G ...), there are equally many hues. Additionally, there are six hues at the boundary between the regions. So, 6 + 6 * huesRY.
In the red-yellow sector, R > G > B, so both arguments to atan2 are positive.
count sqrt(3) * (G-B) / (2R-G-B)
=count (G-B) / (2R-G-B)
=count (G-B) / ((G-B) + (2R-2G))
since we can apply any linear transformation to the sets of [x,y] and not change the count of its ratios, x / (x+2y) == x / y
=count (G-B) / (R-G)
if we subtract the same value from all R,G,B, the ratio does not change, so assume B=0
=count G / (R-G)
=count G / R
so, there are six times as many hues as there are ratios between two positive integers that are both below 2^8 (assuming 8 bits per channel), and six more. There are as many ratios as there are pairs of coprime positive integers. The number of positive integers below n that are coprime with n is called the Euler's totient function. OEIS lists its partial sums. There are exactly 19948 pairs of coprime positive integers below 256.
6 * 19948 + 6 = 119 694
There are exactly 119 694 different hues in the HSV model that correspond to a color in the 8-bit RGB model. Note that they are not spaced evenly.
If 8 bits per channel are used in the HSV model, then there are less colors than in the RGB model with 8 bits per channel simply because some HSV triples map to the same color while every RGB triple defines a different color.
IN RGB color the hues can be calculated from (2^3*depth-2^depth/Luminance)/3= so 15 bit color has 341 distinct hues
24bit color has 21845 Distinct Hues
if there were 119000 hues the remaing colors All hues-Red hues of the red hue would be 256,X,Y around 2^16 which means there are less green and blue hues than red?
RGB<0,128,255> is the named color, Azure, Hue 210 deg.
For RGB<0,n,128> n can only be 0 or 255 to be a distinct hue,
which would be either Navy Blue or Spring Green.
RGB<0,64,128> is a shade of Azure, still 210 deg. It is not a distinct hue.
For RGB<0,n,245> again, n can only be 0 or 255,
which would be either a blue shade at 240 deg. or a cyan shade at 177.65 deg.
Floating point was introduced as a distinction between HSL and RGB (which must be byte valued integers.)
My answer to the original post is a count of distict RGB hues, very focused, and not unproven.
The order of my loops is not arbitrary; it loads an array with the 1,530 unique hues of the full spectrum.
Write it up in C++ or C#, then loop, drawing a line from the top to the bottom of the screen and you will see the full spectrum of unique hues.
I would upload a bitmap, but the denials have kept me from the points I would need for the privilege, and it would probably need to be as a fractalized jpg which ruins the idea, anyway.
'There are 1,530 Hues in RGB(256,256,256) It really is straightforward.
'This effectively reveals the "resolution" of RGB, since to be a distinct hue, one of rgb must be 255, another 0, and the third has 256 values to increment through, less duplicates at the extremes. Everything else is a tint, tone or shade. So, let's add them up in the six combinations of 0 and 255, and also count them up as I, as we go:
Dim I As Integer
Dim R, G, B As Byte
Dim Spectrum(0 to 1529) as Long
I = -1 'Incremented before each use
R = 255: B = 0 'G inc RED
For G = 0 To 255 '256
I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
G = 255: B = 0 'R dec YELLOW
For R = 254 To 0 Step -1 '255
I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
R = 0: G = 255 'B inc GREEN
For B = 1 To 255 '255
I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
R = 0: B = 255 'G dec CYAN
For G = 254 To 0 Step -1 '255
I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
G = 0: B = 255 'R inc BLUE
For R = 1 To 255 '255
I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
R = 255: G = 0 'B dec MAGENTA
For B = 254 To 1 Step -1 '254
I = I + 1: Spectrum(I) = RGB(R, G, B)
Next
'I = 1,529 = 256+255+255+255+255+254 No duplicates
'Hue = I * 0.23529411764705882353°
'0° is Red at I = 0, so I=0 counts as 1 so, 1 + 1,529 = 1530

Resources