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.imread(path + 'manRGBA.png')
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).
And also read about ‘hashing images’.
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 ?