Monday, March 16th, 2009, 1159 days ago
Angle recognition using openCV
Angle calculation using openCV from andol on Vimeo.
In this post, i will present you the new progress of object recognition using openCV—angle recognition.
Actually, this is just a small step further than the last one which is rectangles’ recognition. From the four outlines of rectangle as well as the four corner points, we can get two relative points to calculat the angle between them. As inllustrated below, i chosed two points which are most left and right. Once the position of these two points are captured, the SINE value of the angle can be calculated like this
SIN (angle) = abs(p1.y-p2.y)/sqrt(
(p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y))
So, that’s it.
POSTS MAY BE OF INTEREST
- Writing a simple hand gesture picture sampler for classifier training
- Using hand gestures to control mouse pointer in c sharp
- The error of ‘VIDIOC_QUERYMENU: Invalid argument’
- HIGHGUI ERROR: V4L: index 0 is not correct
- Capturing images from webcams using openCV in Ubuntu 11.04
- Fixing ‘[libavutil/libavutil.so.51] Error 1′ in ffmpeg make for openCV 2.3.1 install
- Installing openCV in Ubuntu with pandaboard part 5 – running openCV 2.3.1 examples
- Installing openCV in Ubuntu with pandaboard part 4 – compiling openCV 2.3.1
- Installing openCV in Ubuntu with pandaboard part 3 – the network proxy
- Installing openCV in Ubuntu with pandaboard part 2
- Installing openCV in Ubuntu with pandaboard part 1
- OpenCV mailing list – a collection of resources
- A review of people counting using openCV part 2
- A review of people counting using openCV part 1
- Using webcams/motion sensing cameras in OMAP-based pandaboard


Do you have source code for the “Angle recognition using openCV” example?
yes i do. leave your email and i ll share it to you.
it’s great
can you send me source code?
thanks
sorry that due to historical evolution of codes, that source code was not kept. but you can refer to the function below which is one of the most important in angle detection:
CvSeq* findSquares4( IplImage* img, CvMemStorage* storage )
{
double s = 0, t = 0;
CvSeq* result;
CvSeq* contours;
CvSeq* squares = cvCreateSeq( 0, sizeof( CvSeq), sizeof( CvPoint), storage );
cvFindContours( img, storage, &contours, sizeof( CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint( 0, 0) );
while( contours )
{
result = cvApproxPoly( contours, sizeof( CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter( contours)*0.02, 0 );
if( result->total == 4 && fabs( cvContourArea( result, CV_WHOLE_SEQ)) > 1000 && fabs( cvContourArea( result, CV_WHOLE_SEQ)) height * img->width/2 ) && cvCheckContourConvexity( result) )
{
s = 0;
for( int i = 0; i = 2 )
{
t = fabs( angle( ( CvPoint*)cvGetSeqElem( result, i ), ( CvPoint*)cvGetSeqElem( result, i-2 ), ( CvPoint*)cvGetSeqElem( result, i-1 )));
s = s > t ? s : t;
}
}
if( s < 0.5 )for( int i = 0; i h_next;
}
//cout << "Rectangles: "<total/4 <<endl;
return squares;
}
hi,Andol. i am beginner of Opencv ,
could you please send me the code of this angle recognition?
thanks !
please refer here locating objects
cheers man!!!
hi , with your code i can get the angle of the BoundingRect (but not the object).
how can i get the object-Angle?
thanks!
Though it might help ‘object angle recognition‘.
Hi Andol,
your way to find angle is different form opencv .
But is your angle finding algorithm work for all angle direction like 0 t8 360 ???
Actually i have to detect hand direction . or any moving object direction .
hi,sir
could you please send me the code of this angle recognition as it is useful in my trajectory finding
@Kutu please check the comments above, the code link has been provided.
hi,Andol.
could you please send me the code of this rectangle‘s recognition?
I am just working on the related area and find your work useful.
Need your help. thanks !
Please check this http://download.andol.info/locatingObjects.cpp
hiii
i want to detect rectangular shape after doing colour detection …of image where all shapes are present.like circle,rectangle,triangle.all are of yellow colour..first i do hsv colour converson and threshholding…but how to detect rectangle after that……
.need ur help urgently….
thanks
@Amit, check the function ‘CVRect locating (IplImage* img,IplImage* output)’, this is the function which does the rectangle recognition work and draws outlines on detection results. So actually the detection of rectangle after thresholds and HSV, this function is the next step to deal with the processed image.
Hope this helps.
hello…
there is a function square.c in the sample of opencv…..
in the function we can get the set of outline points…
but wat i need is the corner points of the square….how to get it using square.c function…..
need help
Hi there, I’ve checked your page and is great, I’m a complete beginner in opencv, I was wondering what fixups must be done to your code to analyze an image instead of a video stream and how to identify triangles based on your square’s code, I really appreciate your help sharing your knowledge on ur site, have a nice day
To change the detecting target from videos to images, the only thing different is to load images through ‘cvLoadImage()’. The other thing to detect triangle instead of rectangles, it is the same for the detection as long as you change conditions to judge detected lines. Cheers.
I have error like this where compile locatingobject.cpp
request for member ‘y’ in ‘p1’, which is of non-class type ‘CvPoint*’. How to fix it ?
thx
hi. can you pls send me the source code.
Hi, I used your function FindSquare4, I´m thinking about change angle recognition, because a trapezoid can be a rectangle if I change perspective, so how can I change the angle recognition to find other angles between 25 and 135?
@Ricardo
If you know coordinates of four points of a square, then you can calculate any angle of this square.