I am still quite new to Python and I would like to create a program which would draw geometry objects of given size. For example how would I create the triangle with the sides of 7cm, 6 cm and 5 cm? Any hint would be very appreciated.
do you want the sizes to be user inputted?
if you do, in my experience I created a loop with the colour and amount of rectangles they wanted by using x=int(number) then for i in range(x): this allowed the user to choose how many rectangles. Before hand I put in an input code to get the answer print("how many rectangles do you want?") and number = input("I want this many rectangles:")
Although it isn't the exact same, if you know what numbers equals what distance you want, then you could redo the x=int(number) for each side and instead move the x from the code i mentioned before to the moving codes. eg,forward(x)
I hope that helped, let me know if you don't understand
Related
enter image description here
My goal is to take the image above and "open" it along the center so that the 9 black doublets are in a straight line rather than in a circle. I have tried using the cv2.toPolar() function in OpenCV but the image is quite distorted, as can be seen below:
enter image description here
I am attempting to try a different approach now. From the center, I would like to access each of the doublet individually, like a pizza slice, and place them side by side
Initially I was thinking of slicing each doublet using two lines from the center of the image to the mid point between the doublets on either side.
My question is: how can I draw contours from the center of the image to the edge of the image, passing through the mid point between any two doublet. If I can draw one, I know that the angle between any two such consecutive contour is 40 degrees.
Any help is greatly appreciated!
I noted a few problems here:
The toPolar() conversion might have been around the center of the image file, but it is not the center of the object. This causes part of the distortion. If you share your code, I could try playing with the code and improving it.
2.The object is somewhat elliptical, not circular. This means you will still have a wave after correcting the above problem.
If you don't mind a semi-automatic solution, you could use OpenCV mouse events to specify the first line and let the program use the 40 degree angle to calculate the rest.
I have this fun idea of a project i'd like to do, but i'm not really sure about the math part of it. Here is the idea:
Make a plastic card that would simulate a 9 finger multitouch gesture when it is held against a capacitive screen
Based on the "9 finger" placement, determine some sort of a unique string and use it as an encryption/decryption key for an app
This way i could just open an app, touch the screen with the card and it would get authorized.
But here's the problem:
It shouldn't matter where you place the card on a screen, because the card would be pretty small to fit various screen sizes
The rectangle in which we can randomly position the 9 "fingers" would optimally be 4.5cm x 3cm
The "finger" itself is only recognized as a touch if it is about a 6mm circle (not sure if this can be made smaller)
I figured we could find the left-top "finger" and get every other "finger's" X and Y difference from it. Then concatenate the resulting numbers into a string and use it as a decryption/encryption key. So basically:
key = concat(X2 - X1, Y2 - Y1, X3 - X1, Y3 - Y1, ...)
But i think such an approach would have very few possible combinations (given a relatively small card size and a relatively big "finger") and one could easily write a program to generate all possible combinations and break the key in no time. Am i right about this? If so, how could i improve this?
Thanks for your thoughts
UPDATE 1: actually tried it out on iOS. The result is not promising, since the "fingers" get detected differently each time. The distance between them varies significantly (by as much as 40 pixels!). So i guess this is not as easy as i expected, since the OS seems to detect the touch differently each time for the same two circles.
Your question is lacking some relevant information: how far apart need the circles be so that the system can still distinguish them? What resolution can you realistically expect for the circle centers? And by “6mm circle”, do you mean 6mm diameter or radius (or even circumference)?
Lacking details, I'll make some pretty rough approximations. I'll start by requiring that two of the circles will be placed in opposite corners of the card. That way, you can find them by looking for a pair with maximal distance, and from that compute the orientation and size of the card and correct for that. This leaves 7 fingers to be placed randomly. I'll assume 1mm resolution, and restrict myself to a 45×30mm area. Which means 39×24=936 positions per circle, for a total of 9367≈6,3×1020≈269 combinations. OK, this does not exclude overlapping circles. But since the card is still rather sparsely covered, that shouldn't amount to too much. I'd say 64 bit of entropy (i.e. 264 possible combinations) should be reasonable even if you enforce non-overlapping circles. If you can really detect the circle centers with the required resolution, that is. This should be sufficient security for most applications. Far better than 8-letter passwords, but worse than the symmetric keys usually used for e.g. AES.
Since all of this depends very much on the resolution, it might be worthwhile to investigate that aspect first. Usually you'll get pixel coordinates for your finger positions, but it would be expecting too much to assume that you'd always get the pixel coordinate closest to the center of your circle. So you might start by writing a small application which draws a 6mm circle and records coordinates it receives. Then place a 6mm artificial circle in that drawn one a large number of times. Look how far the recorded positions differ from the center of circle. Take the maximum of those differences, perhaps after removing outliers. I'd add a pixel or two to that, to account for rounding errors due to the rotation of the card. Then turn that pixel count back into a metric length. This is the resolution you can expect. You might have to do this for several devices. If you do perform these experiments, let me know what you find and I'll update my answer accordingly.
I have an image sequence (video). I would like to count the number of objects in the image sequence. But the main objective is to count them once, meaning not just in each and every frame, since an object may exist in for several frames. My idea is to count the objects as they exit the screen, because of less occlusions. I am thinking of doing this by scanning the bottom part of the image for non zero pixels.
I have a CV_FILLED binary image (from rectangle function) where I want to do the scanning, then create an instance on an object if abject is found. But this scanning will not be scanning each and every pixel along the horizontal line, just certain sections.
Like we could do it over ranges, say certain columns, then skip by a margin.
A sample binary image I have is attached . This is an image obtained from the feed. I do not want to count only the objects in this image, but also those that are still coming.
A full picture of detected objects is attached here.Your guidance or constructive criticism is welcome
* I do not want to use CVBlob
If you don't want to use cvBlobLib, you could use the contour detection that is part of OpenCV.
There is a tutorial on the website.
The doc for the method is here. Your image seem pretty simple, but if you get blobs with occlusions and so you want to look at the CV_RETR_EXTERNAL constant to get only the outer contours.
That is what I usualy use, even though it needs a bit more work to use the results of the method.
Hope this helps.
If the squares do not overlap at the bottom, I suggest the following:
scan the very bottom row of the image and identify those connected pixels which are white. Each white line will correspond to one square. Save the center of the white line segment and its length. In the next frame, do the same and associate the corresponding line segments to the previous (same length and center very close). When you cannot find a corresponding line segment anymore, the square has moved out of the image which means you can increase your squares counter by one. Note that line segments at the right and left ends of the line will have decreasing length with every frame.
Thx guys. I managed to solve this already. I used small ROIs along the paths of the squares, and found countNonZero() within the ROI.
I kept on checking with boolean variables to see if the ROI still had the white pixels. If not, incremented counter. Worked well, and I was able to count.
Thx for your input...
You have 12 shapes:
which you can make each out of five identical squares.
You need to combine the 12 pieces to one rectangle.
You can form four different rectangles:
2339 solutions (6x10), 2 solutions (3x20), 368 solutions (4x15), 1010 solutions (5x12).
I need to build the 3X20 rectangle:
My question what is the maximum number of states (i.e., the branching factor) that is possible?
My half way calculation:
The way I see it, there are 4 operations on each shape: turn 90/180/270 degrees and mirroring (turning it upside down).
Then, you have to put the shape on the board, somewhere on the 3X20 board.
Illegal states will be one that the shape doesn't fit in the board, but they are still states.
For the first move, you can chose each shape in 4 ways which is 4X12 ways, and then you need to multiply in the number of positions the shape can be in, and that is the number of states you have. But how can I calculate the number of positions?
Please help me with this calculation it is very important, it is not some kind of homework which I'm trying to avoid.
I think there is no easy & 'intelligent' way to list solutions (or states) to pentomino puzzles. You have to try all possibilities. Recursive programming or backtracking is the way to do it. You should check this solution that also has java source code available. Hopefully that points you to the right direction.
There is also a python solution that is perhaps more readable.
I know this is more high school math(wow been a long time since I was there) but I am trying to solve this programatically so I am reaching out to the collective knowledge of stackoverflow
Given this layout:
Midpoint is my reference point and in an array I have the vector points of all other points (P)
I can get to this state with code of having the light blue area by breaking it into four quadrants and doing a lame bubble sort to find largest(y) or lowest(x) value in each quadrant.
I need to find only the quadrants that outer border fully hits red no white space. For example the lower left and the up right dont have any white space hitting the light blue rectangle.
I am sure my terminology is all off here and im not looking for any specific code but if someone could point me to a more optimized solution for this problem or the next step in what I already have.
Thank you
I might do some BFI solution first, then perhaps look to generalize it or at least reduce it to a table-drive loop.
So, if it's exactly these shapes, and not a general solution, I think you should proceed sort of like this:
Derive the coordinates of the blue rectangle. I suspect one thing that's confusing you is that you have each individual x and y for the blue rect but you can't easily loop through them.
Derive the coordinates of the midpoint of each rectangle edge. You are going to need this because you care about quadrants. It will be trivial to do this once you have done 1.
Write different code for each 1/2 rectangle edge. There is no doubt a more clever way but this will get working code.
Make it more elegant now if you care. I betg you can reduce the rules to an 8-row
table full of things like 1, -1, or something like that.
First, you can't define red area by a single vector, since it's disjoint. You need the same number of vectors as the number of distant red regions.
Second, do we assume that different red figures neither intersect nor share a border? In the next clause I do.
Third, under assumption in point 2, the quadrant will have all red outer side iff there exists a contiguous red figure that intersects both its axes (i.e. rays). To determine this for all quadrants, you should only traverse all (P) points in the order they're given. This takes linear time and solves the problem.