Ask Your Question

hesperus's profile - activity

2019-09-25 08:50:17 -0600 received badge  Notable Question (source)
2019-09-06 10:15:53 -0600 received badge  Popular Question (source)
2016-07-14 23:39:39 -0600 received badge  Popular Question (source)
2013-03-17 02:40:19 -0600 received badge  Editor (source)
2013-03-17 02:39:15 -0600 asked a question Calculating the mid point in a rotated rectangle side

Hi,

I have a rotated rectangle that is based on a CvBox2D object. The rotated rect contains a moving object, i.e. points of the object.

CvBox2D box = cvMinAreaRect2(pointList)
RotatedRec myRect (box);

I'm trying to calculate the middle point of the two sides (left and right) of this rotating rectangle, i want to know those middle points in each side because that's where my fitting rotating ellipse would be, the problem is I think my math is missing something. for instance, to get to the middle point in the right side, here's what I'm doing:

Point2f rightSide;
float rotationAngle = myRect.angle * (180.0/ CV_PI); // Convert from degrees to radians
rightSide.x = myRect.center.x + myRect.size.width/2; // Get to the middle point
rightSide.y = myRect.center.y; // Keep the y coordinate the same as the center
// Apply the rotation equation, i'm not updating y because I always have the most up to 
// date y coordinate from the center position
rightSide.x = (rightSide.x * cos(rotationAngle)) - (rightSide.y * sin(rotationAngle));

Of course the object is moving randomly within the screen, and so the rotated rectangle is moving along with it. Unfortunately the above piece of code doesn't produce the middle point in the right side of the rotating rectangle, I can tell because I'm actually drawing the point. I'm following a similar approach for the left side. Just wondering if anybody can offer any ideas ? Is it the angle ? Do I have to deal with the fact that sometimes the angle can be in negative and I have to figure out which quarter it lies within ? Is the angle given by the rotated rect is the rotation angle to begin with ? I tried another approach where I get the vertices (i.e. the corners) of the rotated rect and then move to those middle points but that did not work out either.

I'm sure my math is missing something somewhere, I noticed that someone was having a similar problem here (http://answers.opencv.org/question/1945/fast-way-to-draw-ellipse-axes/) but I did not want to hijack the thread.

Appreciate the help, thanks in advance.

2013-02-12 14:59:14 -0600 asked a question Video mask in OpenCV

Hi

I'm just learning OpenCV for a school assignment. I need to mask a specific section of a given video and track the objects within this section. The section is usually specified as a rectangle, and this rectangle represents the section or the slice of the video that needs to be masked. Only objects within this slice or section must be tracked. The rectangle is formulated by getting the x,y coordinates of both the top right corner and the bottom right corner, I have already done this. Now I need to mask those rectangle dimensions out of the video. Attached is a simple representation I made to indicate what exactly should be achieved. The grey rectangle represents the area of the video that should be tracked.

The code is too long to post, but I'm currently reading the video frame by frame using VideoCapture, and every frame is being stored in a matrix (Mat currentFrame).

sample.jpg

I have been reading some things about manipulating the matrix that represents the frame and setting the required pixel values to 0 or something along those lines, but is there any other way ? If anyone could refer me to openCV examples or particular parts of the documentation that I need to look at I would deeply appreciate it.

Thank you.