Reputation: 109
I am developing plate detection algorithm. I made plate localization and now new problem appear. I want to detect plate image rotation angle and rotate if necessary. But how to detect this ? I tried with cv2.HoughLinesP function, but result are as in attached image http://postimg.org/image/vis8errzn/
y = area.shape[0]
x = area.shape[1]
#############################################################################
#If necessary rotate image by angle detected with Hough transformation
gray = cv2.cvtColor(area,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 10
maxLineGap = 30
lines = cv2.HoughLinesP(edges,1,math.pi/180,100,minLineLength,maxLineGap)
if(lines != None):
for x1,y1,x2,y2 in lines[0]:
cv2.line(gray,(x1,y1),(x2,y2),(0,255,0),2)
a = ((y2-y1)*1.0)/((x2-x1)*1.0)
print 'a = ', a
print 'lines = ', lines
Upvotes: 0
Views: 3342
Reputation: 6146
I am not positive what kind of "plate" you are referring to but I assume it is some planar object with notable features. In either case, here is an excellent tutorial by the folks at OpenCv explaining how to determine what I believe your question is asking:
http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html
The basic run down for this procedure is:
- Given the image files for the plate in question (in the orientation you want to consider)
- Detect feature points in both images
- Use a descriptor on those feature points to give them "meaning"
- Match the descriptors between the two images
- Calculate the Homography between the two images (giving you the rotation matrix you are looking
for)
All of this can be done with opencv standard library functions.
Upvotes: -1