Ask Your Question
0

Get the each coodinates of all corner of 2 rectangle

asked 2016-01-04 03:23:59 -0600

tenkeason gravatar image

updated 2016-01-04 03:26:15 -0600

May i know how to get the coordinate of each corner rectangle? Means i need get 8 coordinates of corner from there.

image description

edit retag flag offensive close merge delete

Comments

show us, what you tried so far.

berak gravatar imageberak ( 2016-01-04 03:30:06 -0600 )edit

My full codes was under comments which is "main", "color.h", "color.cpp" and already use the comments code to get the rectangle, and this is the link. http://answers.opencv.org/question/81...

tenkeason gravatar imagetenkeason ( 2016-01-04 03:51:58 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-04 10:27:16 -0600

i hope the code below helps you.

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;

int main()
{

    Mat src = Mat::zeros( 400, 400, CV_8UC3);

    Rect r(100,100,50,50);

    Point point0 = Point(r.x, r.y);
    Point point1 = Point(r.x + r.width, r.y);
    Point point2 = Point(r.x + r.width, r.y + r.height);
    Point point3 = Point(r.x, r.y + r.height);

    rectangle( src, r, Scalar::all(255));

    circle( src, point0, 10, Scalar( 0, 0, 255) );
    circle( src, point1, 10, Scalar( 0, 0, 255) );
    circle( src, point2, 10, Scalar( 0, 0, 255) );
    circle( src, point3, 10, Scalar( 0, 0, 255) );

    imshow( "coodinates of all corner of rectangle", src );
    waitKey();

    return 0;
}
edit flag offensive delete link more

Comments

May i know what should I change or add this code in my ori code? http://paste.ideaslabs.com/show/baMTo...

tenkeason gravatar imagetenkeason ( 2016-01-04 19:36:06 -0600 )edit

what is your desired final result? you must to give some effort to complate your code.

sturkmen gravatar imagesturkmen ( 2016-01-04 21:04:45 -0600 )edit

Actually this is my Final project about obstacle avoidance and i just starting using opencv less than 2 months, but now i need to complete my first part project that is detect the obstcle using opencv.

tenkeason gravatar imagetenkeason ( 2016-01-04 22:26:38 -0600 )edit

Finally i get the corner from rectangle like this picture. thanks for your help sir http://pasteboard.co/yEnWjGb.jpg

tenkeason gravatar imagetenkeason ( 2016-01-04 22:27:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-04 03:23:59 -0600

Seen: 9,906 times

Last updated: Jan 04 '16