I have coordinates for 2 corners https://prnt.sc/w2jryh (x and y coordinates for d and b points of the square). And I need to create screenshot within the area of this square, but when I am trying to do that, it is failing, either getting too much in screenshot, or too less. What may be the magic formula for that :) This is what I tried:
pyautogui.screenshot("testScr.png",region=(blackRookCornerX,whiteRookCornerY,whiteRookCornerX,blackRookCornerY))
basically taking coordinates and trying get the right screenshot. Coordinates are correct here.
From their docs
There is also an optional region keyword argument, if you do not want a screenshot of the entire screen. You can pass a four-integer tuple of the left, top, width, and height of the region to capture:
The first two numbers should be the x,y coordinates of the top left corner of where you want to take a shot, the third number is how far right/left to go (in pixels) and the fourth is how far up/down to go (in pixels).
Try this:
pyautogui.screenshot("testScr.png", region=(blackRookCornerX, whiteRookCornerY, 100, 100))
Start with a broad number like 100 and then slowly whittle away until you have the perfect screenshot.
You could make a hotkey to use for each corner, to collect the coordinates; Simply put your mouse in those corners and press each hotkey. Then once you have done that for both corners and have two variables, use those variables for your screenshot.
Related
So for a project, I gotta make a web-site that fills a shape with circles that wont intersact at any point.The user is going to upload a shape, and also choose the radius of the circles, and the code is going to place as many circles(with the chosen radius) as it can into the shape.
For example, if the user uploads an 16cmx16cm square and chooses 4cm as the radius of the circles, the system is going to place as many circles with a radius of 4cm as possible into the square, and the circles wont intersact at any point.
I tried many things using python and failed eveytime. The shape can be anything, it can be completely random and no matter what the shape is, the site has to find out where to place the circles with the selected radius, place the circles, and show the final shape. I dont know if there is a way to do this without python, but I am open to every suggestion-solution.
You could try the package circle-packing. It looks like you can get the behavior you want by setting the arguments rho_max and rho_min of the class ShapeFill to the radius provided by user. I've not used it so cannot attest to its' correctness or usability. Please let us know if it works for you.
Note: The license is GPLV2 so keep in mind the implications. And don't forget to attribute.
I believe filling it with the actual possible maximum amount would be far from easy, if you actually just want fill it and don't care about the best solution then it's fairly easy.
just start to for the top left corner place a circle, if collides with another circle or the shape it, shift it to the right of an arbitrary small amount and try again. once you reached the end on the right side, move it down and to the left and start the process again.
I'd like to find the corners of the following box
However, as you can see I'm detecting a lot of corners I don't want to find. I'm completly stuck on this one. No matter what I try, I always seem to find corners in the dots on the box. I used the function goodFeaturesToTrack() but I also tried cornerHarris()
The most important thing to me is to find the coordinates of the corner pixels so I can draw a wire frame.
Kind regards, Schweini
Edit:
To draw the wire frame onto the image, following process can be thinkable.
When extracting outline of the black box region, the outline consists with 6 straight line segments.
Therefore, you'll able to find at least 6 corners of the box as the intersection of each two adjacent line segments.
Additionally, it looks like that, outline of 6 surfaces of the box will be able to coarsely estimated from each adjacent line segment pairs. (with assuming parallelogram)
This means estimating the positions of the remaining two corners (to draw the wire frame).
Furthermore, if you want, comparing the estimation result with your examination (corner detecition) result will be able to refine the coordinates of one corner.
I'm trying to get coordinates of billiards table's side point.
This is origin image
in this image to
This black point's coordinates
This black point's coordinates
because i need to get edge's coordinates even when something hide some part of the image, like that way if i can get two arbitrary points in one side of table i can calculate the edge points.
but i have no idea how can i get that point...
please help. thanks for reading
This question already has answers here:
How do I rotate an image around its center using Pygame?
(6 answers)
How to rotate an image(player) to the mouse direction?
(2 answers)
Closed 2 years ago.
I'm making a heads-up display, similar to what you'd find in a fighter jet (http://i1.ytimg.com/vi/RYjBjT79hLo/hqdefault.jpg).
Some of the elements just stay in one place on the screen, like the airspeed and altitude. That's easy.
The part I'm having trouble with is the pitch ladder (the bars that show 5, 10, 15, etc degrees above/below the horizon) and horizon line. The way I'm trying to implement it is to have a png file that has all the bars from -90 to +90 already created. This file is much much larger in resolution than my display window, so only the bars that correspond to the current pitch, +/-10 degrees, are displayed on the screen. As the user pitches up, the image moves down, and vice versa. As the drift angle increases (the angle between the heading and the velocity vector, ie, sideslip), the HUD moves left or right. The problem is in rotation. I'd like to be able to specify the location of the center point of the image and the rotation angle, not just the top left corner, and have pygame render it appropriately. I'm not quite clear on exactly how rects work though, which is part of the problem.
My math background tells me the easiest way to do this would be to get an array of each pixel value on the screen, then multiply by a transformation matrix based on the pitch and roll, but I don't think pygame actually lets you access that low-level information.
[EDIT] On second thought, a pixel array may not be easiest. A transformation matrix edits the values of each element in the array, but a pixel array contains RGB information in each element. A transformation matrix would just edit the color of each pixel, not actually transform them. hmmmm.... [/EDIT]
It seems like pygame really really wants everything to be boxed up in rectangles that are parallel to the screen borders, which is kind of a problem for a rolling aircraft. I've thought about using OpenGL instead, but that seems overkill. Can anyone help me do this in pygame? Thanks!
The script below works perfectly when I want to click, for example, the Start button on Windows, but when I try to click a button in a certain GUI program it does not have any effect.
Is it possible that this program has disabled virtual mouse clicks?
If so, can I circumvent this somehow?
import win32api, win32con
Po=win32api.GetCursorPos()
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,Po[0],Po[1],0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,Po[0],Po[1],0,0)
mouse_event (and SendInput, which is the preferred API to use for input) have a couple of tricky bits, it's a good idea to
read the MSDN page for mouse_event fully and carefully before using it - pay attention to the small print: in particular, the x and y values are not pixels, so you can't just put in values you get from GetCursorPos.
It just happens that 0,0 is the bottom-left corner, so points near the bottom left will be roughly in the same area of the screen, but the further away from that you get, the more the pixel values diverge from the actual units that this API uses: so it can appear to work for positions near the start button (assuming it's in the bottom left of the screen), but for other values, it may appear to be clicking somewhere else, which sounds similar to what you are seeing.
From MSDN:
dx [in]
Type: DWORD
The mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the mouse's actual x-coordinate; relative data is specified as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.
So first of all, you need the MOUTEVENTF_ABSOLUTE flag. But that's not all:
Remarks
...
If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.
...so you'll need to scale your target coordinates appropriately before passing them to this API.
Mouse events generated by programs have an "injected" property that an app can filter if they want - for example MMO clients often filter those to avoid bots
Those zeros in the mouse_event let you set some properties, you might want to research if those will let you overcome the injected flag, although I can't find a way immediately
below code worked for me
pyautogui.mouseDown(fromx, fromy)
time.sleep(2)
pyautogui.mouseUp(tox, toy)
pyautogui.mouseUp(1000,400)