My requirement is to draw a rectangle on an image using program and allow the user to fine tune the length/width position with the mouse. And, get back the modified details into the program. I am using OpenCV, Linux.
Currently I am using library function to draw the basic shape on the image
polylines(image, &p, &n, 1, true, Scalar(0,0,255), 2, LINE_AA);
I understand the shape drawn here is part of the image and not treated as a layer above the image. Harder way to achieve what I want is
Highlight the shape by placing small filled circles at the corners and filling the shape by translucent color, upon mouse click
track the mouse drag and move the corners accordingly to re-size the shape, if first clicked on the corner circles
if clicked within, move the shape itself
The program has to continuously check for mouse clicks, track their movement and keep drawing shapes at new position to give user the feedback.
Is there any single function to achieve the same or any easier method?
Thank you.
Related
So first some background. Im developing a really simple 2D game, in Delphi 10.3, FMX, which at the bottom of the screen draws a random terrain for each level of the game.
Anyway, the terrain is just some random numbers which are used in Tpathdata and then i use fillpath to draw this 2d "terrain".
I want to check when a "falling" object, a trect for example, intersects with this terrain.
My idea was to get all the points of the tpathdata, every Y position of every X position of the screen width. This way i could easily check when an object intersects with the terrain.
I just cannout figure the way how to do it, or if anyone has any other solution. Id really appreciate any help. Thanks
This is not really a Delphi problem but a math problem.
You should have a math representation of your terrain. The polygon representing the boundary of the terrain. Then you need to use the math to know if a point is inside the polygon. See Wikipedia.
You may also implement it purely graphically using a B/W bitmap of the same resolution of the screen. You set the entire bitmap as white and draw the terrain on the bottom in white. Then checking the color of a pixel in that bitmap you'll know if it is outside of the terrain (black) or inside the terrain (white).
I have a list view with "Hero" icons on the left. When I click a list item, it loads the next screen with the article text and the Hero image (which animates nicely/automatically to the correct spot on the 2nd screen).
I would have thought that was the "tough" part, but I'm now trying to get a curved shape as the top background of the 2nd screen. I would love to make it a drawn vector shape, as opposed to a bitmap and even have it drip/bounce onto the page, but at the moment...
I'm just trying to figure out how to:
draw a vector shape
have it as the background of a screen with other widgets on top (see purple curve on 2nd screen below)
I made a full sample for your curved shape in a gist here
I used CustomPainter to draw on a canvas then, with some geometric calculations, I achieved the curved shape.
Final result
How I draw it?
Before coding and on a Whiteboard I determined somethings:
My Canvas Area:
The canvas dimensions I need to draw that shape (which equals to Flutter widget's dimensions).
How and where my brush will move?
how means: what are the APIs I need to draw that shape on the canvas using the Path class.
e.g. lineTo() for a straight line, quadraticBezierTo() for a curve.
where means: Where are the points (coordinates) I need to draw the whole shape. (see yellow and green dots in the image above)
Points (coordinates) Calculations:
I used some geometric equations to calculate the coordinates. e.g. Point on a circle’s circumference
All of my calculations depend on the canvas size, that gives me a responsive shape.
Full sample here!
This is an example of a drawing for the program I use
DrawCircle(mousePos.x, mousePos.y, mousePos.z, 650, ARGB(255, 255, 0, 0))
pretty simple x,y,z location radius of the circle and color, in this example it will draw a circle around my mouse and if my mouse moves the circle moves with it as is should, however what I would like to do is know how to draw a circle at lets say stationary position x,y,z and make the circle move from said position to new position a,b,c at x speed. sure I can just disable the draw at the starting point and redraw it at the destination point but I want the circle to visually move from point a to point b at speed x and I'm not sure what math I would need to be able to do this, furthermore if I was to draw a line how could I rotate that line in place so it looked like lets say helicopter blades spinning? Any help is appreciated thank you.
Not sure about LUA per se, but the solution to your problem is based around vector mathematics. LUA may have provide transformation functions to move a point in 3D space... not sure. As for the rotor blade question, if you are plotting the rotor blade in a 2D plane, you simply need a bit of trigonometry. There are lots of examples on the web, e.g.: trig example
I am trying to crop a picture on right on along the contour. The object is detected using surf features and than i want to crop the image of extactly as detected.
When using crop some outside boundaries of other object is includes. I want to crop along the green line below. OpenCV has RotatedRect but i am unsure if its good for cropping.
Is there way to perfectly crop along the green line
I assume you get you get your example from http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html, so what you can do is to find the minimum axis aligned bounding box around the green bounding box, crop it from the image, use the inverted homography (H.inv()) matrix to transform that sub image into a new image (call cv::warpPerspective), and then crop your green bounding box (it should be axis aligned in your new image).
You can get the equations of the lines from the end points for each. Use these equations to check whether any given pixel lies within the green box or not i.e. does it lie between the left and right lines and between the top and bottom lines. Run this over the entire image and reset anything that doesn't lie within the box to black.
Not sure about in-built functionality to do this, but this simple methodology is guaranteed to work. For higher accuracy, you may want to consider sub-pixel checks.
Every CCSprite is a regtangle area, but some of the parts of it, is visible ,means image that we see and other part are not. So i want to know when i touch on CCsprite whether the touch point is visible area or transparent area, Any way to check this, like getting the pixel color of the touch point??
It's possible to do this with OpenGL API, but it would be wrong solution. I propose to detect tap point inside sprite shape (that would be manually defined). To calculate bounding shape you may use for example this tool: SpriteHelper. To check point inside polygon (even non-convex) there is good algorythm: Determining if a point lies on the interior of a polygon. I use this method in my iPhone game.
As for efficienty of this method compared to direct checking of pixel opacity:
performance: to get pixel in OpenGL you need to lock texture and read data from it, this will drop FPS
accuracy: tap is not a mouse click, it means some region, so you would probably check some area (for example circle of tap) inside sprite shape
flexibility: you may tune your shape as you want
PS: If you definitely want to check pixels, a good solution will be to make additional boolean map of texture pixels (where each bit responds to pixel treshold).