Ask Your Question
0

How to translate the Region of interest to the Center of gravity of the image?

asked 2017-01-22 06:53:53 -0600

Allison gravatar image

updated 2017-01-23 00:44:42 -0600

I'm using Opencv 3.0 c++.I have been able to find the COG of an irregular object but now I need to translate the ROI to the COG of the image,that is to make it in the center.

Any suggestions how to do it?

image description

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-01-22 07:24:27 -0600

LBerger gravatar image

updated 2017-01-22 10:42:07 -0600

if topleft corner (M) of ROI is (xr,yr) in orignal image (origin O) and gravity center (G) of contour is(xg,yg) in roi coordinates then gravity center coordinates in orignal image is (xr+xg,yr+yg).

or

if topleft corner of ROI is (xr,yr) in orignal image and gravity center of contour is(xg,yg) in image coordinates then gravity center coordinates in roi is (-xr+xg,-yr+yg).

OM+MG=OG

If you want to move all points belonging to a contour :

Point d(100,200);// translate vector d
for (int i=0;i<contour.size();i++
     contour[i] += d;
edit flag offensive delete link more

Comments

Do you want to move contour ? If yes you have to move all contour points

LBerger gravatar imageLBerger ( 2017-01-22 09:51:59 -0600 )edit

Yes i want to move the contour

Allison gravatar imageAllison ( 2017-01-22 10:35:34 -0600 )edit

@LBerger Thank you

How to use the function to align ?

Allison gravatar imageAllison ( 2017-01-23 00:06:51 -0600 )edit
0

answered 2017-01-22 09:45:54 -0600

Allison gravatar image

I have been using the following code:

//Translate the ROI to the COG of the image
    int x;
    if (COG.x > center.x)
    {
        x = COG.x - center.x;
        x = -x;
    }
    else
    {
        x = (COG.x - center.x)*-1;
    }

    int y;

    if (COG.y < center.y)
    {
        y = center.y - COG.y;
    }
    else
    {
        y = center.y - COG.y;
    }

But still no output.The object is not being positioned at the center. Did i made any mistake for the translation?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2017-01-22 06:53:53 -0600

Seen: 876 times

Last updated: Jan 23 '17