I am using python with OpenCV and pyautogui to play the game tetris (via a website) with your hands. In order to play the game there are 4 directions (up/down/left/right) that I want to detect to match with inputs for the pyautogui. I have tried so many ways to detect the direction of the finger that it pointing but nothing works consistently,any help on the current solution I am working on, or another idea would be great.
I am currently trying to use findContours with convexHull to detect the perimeter of the hand and attempt to find the sides with the smallest angle which in turn should tell me the side the finger is pointing. But I don't know how to extract that information.
I have tried using a BoundingRect to find which side is longer (w or h) then splitting the rectangle in half and seeing which side has more pixels in it (from the binary of the contour), but it wasn't consistent enough.
I have also tried using HoughLines and HoughLinesP to find a vanishing point, but I couldn't figure out how to get that to work.
Basically I am at a loss.
Edit: I'm trying to avoid MediaPipe so I can show I understand how to use the elements of openCV
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'm looking for some advice on what to use for this problem.
I have a camera feed of a flat surface. I want to be able to mark a point on that surface, and then to automatically track the movement of that point in the frame. In other words, I want to track the shift and rotation of the image compared to the initial state.
I think this should be possible using opencv or something similar, but I'm unable to find the right tools.
Could someone point me in the right direction?
Preferably some way in python but other methods are welcome too.
I'm looking forward to developing a Rubik's Cube solver (just for fun). For this, the user would take a picture of the cube in a way that three sides of it are visible, like in this picture:
cubeA.jpg:
It can be safely assumed that the cube is covering most of the picture. Now, what I would like to do is detect the exact orientation of the cube. That is, I am interesting in detecting these seven points:
cubeB.jpg:
From this, I would be able to split each of the three faces into 3x3 grid and detect the colors (for which I have already written the code and which works quite well).
Now, I have made a few attempts to solve this problem using corner detection and contour extraction in OpenCV. None of them have been satisfactory, however. Another way of looking at this problem would be to recognize each of the 27 little, so-called “facelets”, and detect the orientation using those. But I'm not sure if that's the right approach either.
How would you go about solving this problem using OpenCV?
I'm currently working on my first assignment in image processing (using OpenCV in Python, but I'm open to any libraries and languages). My assignment is to calculate a precise score (to tenths of point) of one to several shooting holes in an image uploaded by a user. The issue is that the image uploaded by the user can be taken on different backgrounds (although it will never match the rest of the target mean colors). Due to this, I have ruled out most of the solutions found on the internet and most of the solutions I could come up with.
Summary of my problem
Bullet holes identification:
bullet holes can be on different backgrounds
bullet holes can overlap
single bullet holes will always be of similar size (there is only one type of caliber used on all of the calculated shooting targets)
I'm able to calculate a very precise radius of the shooting hole
Shooting targets:
there are two types of shooting targets that my app is going to calculate (images provided below)
photos of the shooting targets can be taken in different lighting conditions
Shooting target 1 example:
Shooting target 2 example:
Shooting target examples to find bullet holes in:
shooting target example 1
shooting target example 2
shooting target example 3
shooting target example 4
shooting target example 5
What I tried so far:
Color segmentation
due to the reasons mentioned above
Difference matching
to be able to actually compare the target images (empty and fired on), I have written an algorithm that crops the target by its outer largest circle (its radius + bullet size in pixels)
after that, I have probably tried all of the ways of images comparison found on the internet
for example: brute force matching, histogram comparisons, feature matching and many more
I failed here mostly because the colors on both compared images were a bit different and also because one of the images was sometimes taken in a slight angle and therefore the circles weren't overlapping and they were calculated as differences
Hough circles algorithm
since I know the radius (in pixels) of the shots on the target I thought I could simply detect them using this algorithm
after several hours/days of playing with parameters of HoughCircles function, I figured it would never work on all of the uploaded images without changing the parameters based on the uploaded image
Edge detection and finding contours of the bullet holes
I have tried two edge detection methods (Canny and Sobel) while playing with image smoothening algorithms (like blurring, bilateral filtering, metamorphization, etc..)
after that, I have tried to find all of the contours in the edge detected image and filter out the circles of the target with a similar center point
this seemed like the solution at first, but on several test images it wouldn't work properly :/
At this point, I have ran out of ideas and therefore came here for any kind of advice or an idea that would push me further. Is it possible that there simply isn't a solution to such complicated shooting target recognition or am I just too inexperienced to come up with it?
Thank you in advance for any help.
Edit: I know I could simply put a single color paper behind the shooting target and find the bullets that way. This is not how I want the app to work thought and therefore it's not a valid solution to my problem.
I am new to OpenCV. I am working on a project that involves tracking and detecting a spinning roulette ball. Here is the video I want to use: https://www.youtube.com/watch?v=IzZNaVQ3FnA&list=LL_a67IPXKsmu48W4swCQpMQ&index=7&t=0s
I want to get the ball time for 1 revolution. But the ball is quite fast and hard to detect. I am not sure how to overcome this.
What would be the best algorithm for doing this?
By subtracting successive images, you will isolate the ball as a (slightly curved) line segment. Both its length and its angular position are cues for the speed.
Anyway, these parameters are a little tricky to extract for a side view, as the ellipse has to be "unprojected" to a top view, to see the original circle. You need to know the relative position of the wheel and the viewer, which you most probably don't know.
An approximate solution is obtained by stretching the ellipse in the direction of the small axis.