# In need of help from an OpenCV 'rotation guru'

Hi,

So I know this is perhaps a strange question, but I understand how rotation works in OpenCV, what with defining a rotation matrix and then using warpAffine. However, I kind of have a specific requirement for it:

Namely, either from the center, or the bottom of the image, I need it t0 rotate around a poi9nt that is 50-70 inches below (basically along the radius of a ‘really big’ circle)-- But I am really not sure how to do this, or otherwise convert pixels to inch measurements to define my rotation matrix.

Alternatively there is another way to think of this problem: Given a stated or specified arc of a circle (with said distances), well, I need my image rotation to follow along this arc.

Unfortunately, I have no idea how to accomplish this.

Any assistance would be greatly appreciated.

Best,
-A

I

please, have another look at the tutorial (the Rotation part)

then, forget about ‘inches’ or the like, simply, the ‘center’ point (for cv.getRotationMatrix2D ) needs an y-offset of so-and-so-many pixels downwards (the ‘circle radius’).
vary the angle, and it will ‘follow an arc’

I will review the tutorial again. To be honest the only reason I mention ‘inches’ (I do understand computer images don’t work in such terms), but I am trying to utilize OpenCV to do a ‘pre-rendering’ stage for an actual ‘real-world’ (i.e. embedded) project and the rotation vector will have these requirements.

In the end it might require a bit of ‘guess and check’, but even your reply, at least it gave me an idea. I could create a ‘typical’ image in Photoshop, add the Y dimensions in inches (and this is why I asked-- at least Photoshop let’s you specify images by physical dimensions at a given resolution-- I wasn’t sure if OpenCV had the same) and then count the number of pixels I’d have to add for the radius. That might work.

Further I do understand this is not a task OpenCV is usually used for, but I am between this and ImageMagick, or just writing my own ‘double-shear’ algorithm… But sometimes, you know, no sense ‘reinventing the wheel’ when you are actually trying to design the cart. If you know a better library to use, let me know.

Best,
-A

some images have “physical dimensions” because they carry a “pixels per inch” value, which is only relevant for printing. it is a completely arbitrary and meaningless value.

we can’t help without an accurate presentation of the issue, which should emphasize data (pictures) and possibly code. text is imprecise.

Dear Crackwitz,

My application actually is 'printing related, so at least I don’t sound like ‘naïve nut’ here, but unfortunately at this time I am not in the position to relate more. If I could share the drawings/animations, I promise you guys would just ‘get it’.

However, since this is OpenCV, as an inspiration in return, for someone much smarter than me, it would be really cool to have a function that would allow an image to follow along an arbitrary mathematically defined curve-- my example of a ‘circle’ is obviously like, the easiest one, but I am not yet aware of any library or even program that lets you do that.

I mean, yeah, Photoshop will let you do ‘text on a path’-- But animation, or movement of an image in this way… At least personally it could have a lot of cool and important applications, from design to other realms.

But at the moment I am kind of ‘stuck with’ the problem I am working with/on.

Thanks guys though for ‘jogging my brain a bit’.

Best,
-A

warping an arbitrary picture along an arbitrary path?

for a circle, it would be somewhat simple because it’s easy to invert the mapping and simply take each destination pixel, look up its source point, and sample the source image there (that’s how interpolation works).

for arbitrary paths, you’ll have to look into OpenGL or other drawing libraries. you’d define your graphic (text) as a texture, then make a mesh, and deform the mesh suitably, then have the library draw the textured mesh.

Yes, well if I believe I am understanding you right, that would be like pulling an F-16, when all you really need is a Cessna. Yeah if you have to jump to 3D transforms too, I could see the need for it: But since OpenCV is a library, not an actual ‘drawing application’, you’d need to feed the function with an f(x) curve.

That said, I’ve also considered an application where you trace out like a random Bezier curve, and then like ‘load the gun’, so to speak, with images you all want to automatically lay out at normals to that curve. At least in Photoshop, or InDesign, I don’t know you can do that.

Perhaps by hand-- And super patiently, but there seems ‘no reason’ this couldn’t be automated. And I think it would be ‘really cool’.

But, no worries, just like I said I’m only trying to figure out how to go in ‘very big circles’, and do I use a library or do I crack my own using the shear method ?

Dear Crackwitz, Berak,

Thank you for your earlier assistance. I reread the tutorial and think I made some progress here.

My goal, essentially is to ‘scan’ the image and capture the relevant pixel data along a line during rotation.

I have a short video here of what this looks like so far:

And also the code:

``````import cv2 as cv

DEF_ANGLE = 0

cv.namedWindow('window')
path = 'Resources/'
img = cv.resize(img, (0, 0), fx = 0.2, fy = 0.2)

while (True):
DEF_ANGLE -= .05
num_rows, num_cols = img.shape[:2]
rotation_matrix = cv.getRotationMatrix2D((num_cols/2, num_rows/2), DEF_ANGLE, 1)
img_rotation = cv.warpAffine(img, rotation_matrix, (num_cols, num_rows))

img_rotation[ :,390] = [0, 0, 255]

cv.imshow('window', img_rotation)
k = cv.waitKey(1) & 0xFF
if k == 27:
break

cv.destroyAllWindows()
``````

At first… I was a little ‘confused’ because the ‘.shape’ of img_rotation never seems to change size. It is almost as if the image is somehow being rotated within itself.

Plus also that my ‘red line’ (that would be the line I’m scanning with or:

``````img_rotation[ :,390] = [0, 0, 255]
``````

doesn’t completely start to fill the image. I understand better now that img_rotation gets completely rerendered with each call, and if I wanted to make changes, I’d have to write to img instead.

However, for my purposes, I think I have another question: For one, since I am not just doing ‘images on a screen’, drawing a straight line across to draw out pixel color data, is there any way to add perhaps, any another element or column, without OpenCV, or Numpy like, ‘totally freaking out’ about the dimension space ?

I mean, yes, I know this is important-- And I’ve read a number of papers about this, and even presently, it is hard, except at ‘very explicit’ rotations (90, 180, 270, etc).

My thought is if you could attach a hash code to every pixel in the array at the… Well, ‘0’ degree angle, when you try to find, even after rotation, ‘what this pixel is’ or the `[x][y]`, in the original image, you could do that-- even after rotation or translation.

I mean I have considered another way this ‘could’ be possible, but it is not ‘elegant’.

And no I’ve seen some ‘very advanced’ solutions that go to the level of like ‘identifying features in the image or such’ and no-- No, I don’t need that ‘level of madness’.

My problem with rotation, for my application is ‘I cannot hit the same speedbump twice’-- that would be bad. I mean I know there are dicts and sets-- And if there are copies of duplicate elements, they have to be weeded out. And if I had the same reference, in rotation, I could say, just ‘oh, let’s ignore this point’-- not ‘double add it to the set’.

Before I set out on trying my ‘very difficult’ way, can either of you think of some better way I can do this ? And again, in my case, I am dealing with a ‘known image’, and working with that. I am not trying to deal with the much harder question of image classification-- (i.e. trying to take an unknown rotated image and finding a set other rotated images that match)-- No, no.

Just if I ‘rotate it’, I need to pick out the original points so that I have no ‘duplicates’.

Guys, any thoughts ?

And also, before you ask, in the video presented, I am pretty sure I am not going to get ‘duplicates’. But please consider the question I originally asked- Given the ‘huge radius’, closer to the center of the circle, I am pretty sure I am… And I just need to ‘eliminate that’.