# Finding angle of rotation of an image after comparing with the target image

**URL:** <https://forum.opencv.org/t/finding-angle-of-rotation-of-an-image-after-comparing-with-the-target-image/11371>\
**Category:** Python\
**Created:** [December 21, 2022, 3:45am UTC](https://forum.opencv.org/t/finding-angle-of-rotation-of-an-image-after-comparing-with-the-target-image/11371 "2022-12-21T03:45:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohit\_Thakur](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rohit_thakur/32/6790_2.png) [@Rohit\_Thakur](https://forum.opencv.org/u/Rohit_Thakur)\
**Post date:** [December 21, 2022, 3:45am UTC](https://forum.opencv.org/t/finding-angle-of-rotation-of-an-image-after-comparing-with-the-target-image/11371/1 "2022-12-21T03:45:18Z")

</div>

Hello,

I have a target image and a detected image of same object which is rotated.  
I would like to compare the 2 images and find out the angle which gives highest comparison confidence.  
 ![target](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/5/55c7e8bc72e96803adb5461b13c2324f78be543f.png)

---

<div class="post-metadata">

**Author:** ![Rohit\_Thakur](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rohit_thakur/32/6790_2.png) [@Rohit\_Thakur](https://forum.opencv.org/u/Rohit_Thakur)\
**Post date:** [December 21, 2022, 3:46am UTC](https://forum.opencv.org/t/finding-angle-of-rotation-of-an-image-after-comparing-with-the-target-image/11371/2 "2022-12-21T03:46:29Z")

</div>

The above image is the target and below is the detected image.  
 ![obj](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/9/938660f2b09e889c858902c5a755984918333810.png)

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [December 21, 2022, 8:56am UTC](https://forum.opencv.org/t/finding-angle-of-rotation-of-an-image-after-comparing-with-the-target-image/11371/3 "2022-12-21T08:56:31Z")

</div>

Hi,  
If you have always le black ellipsoid use [moment](https://docs.opencv.org/4.x/d0/d49/tutorial_moments.html)

---

<div class="post-metadata">

**Author:** ![Rohit\_Thakur](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rohit_thakur/32/6790_2.png) [@Rohit\_Thakur](https://forum.opencv.org/u/Rohit_Thakur)\
**Post date:** [December 21, 2022, 4:37pm UTC](https://forum.opencv.org/t/finding-angle-of-rotation-of-an-image-after-comparing-with-the-target-image/11371/4 "2022-12-21T16:37:47Z")

</div>

Currently I am using opencv contour and minarearectangle to find the rotated boundong box and than match template function matching. But this approach gives different contours all than because of various reason like light, reflection and hence the rotated angle from minarear rectangle is not stable.Any suggestion how can i find the top point of the images.?
