Looking for some solution for following type of image , I want to make it flat and straighten for further comparison. I tried searching but some solutions here on stack overflow didn't work
import numpy as np
import cv2
from scipy import ndimage
image1 = cv2.imread('image.jpg')
gray=cv2.cvtColor(image1,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
canimg = cv2.Canny(gray, 50, 200)
lines= cv2.HoughLines(canimg, 1, np.pi/180.0, 250, np.array([]))
#lines= cv2.HoughLines(edges, 1, np.pi/180, 80, np.array([]))
for line in lines:
rho, theta = line[0]
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))
cv2.line(image1,(x1,y1),(x2,y2),(0,0,255),2)
print(theta)
print(rho)
img_rotated = ndimage.rotate(image1, 180*theta/3.1415926 + 180)
cv2.imshow("img",img_rotated)
cv2.waitKey(0)
#closing all open windows
cv2.destroyAllWindows()
This did very slight straightening I am not expert at OpenCV but I it didn't work.
The above code does very slight adjustment. I know it doesnt do any flattening work. I am looking for something related to this.