1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
def rectif(In, cadreIn, cadreOut):
Out = cv.CloneImage(In); cv.Zero(Out)
mmat = cv.CreateMat(3,3, cv.CV_32FC1)
print ("mmat= %s"%repr(mmat))
cv.GetPerspectiveTransform(cadreIn , cadreOut, mmat)
cv.WarpPerspective(In, Out, mmat)#, flags=cv.CV_WARP_INVERSE_MAP )
return Out
# Classe
...
##methode de classe concernee
def launch_rectif(self):
global current_image
#Extraction des coordonnees laser array (4,2)
self.coord_laser = extraction_laser(current_image)
#conversion tuple
coord_laser = tuple((tuple(self.coord_laser[0]),\
tuple(self.coord_laser[1]),\
tuple(self.coord_laser[2]),\
tuple(self.coord_laser[3])))
#Calcul des coordonnees laser dans le cas orthogonal
height_laser_pix = 0.5*74.5/self.taille_pixel[0]
width_laser_pix = 0.5*74.5/self.taille_pixel[1]
image_center = np.array([np.sum(self.coord_laser[:,0])/4.0,np.sum(self.coord_laser[:,1])/4.0])
self.new_coord_laser = tuple(((image_center[0]-height_laser_pix, image_center[1]-width_laser_pix),\
(image_center[0]-height_laser_pix, image_center[1]+width_laser_pix),\
(image_center[0]+height_laser_pix, image_center[1]+width_laser_pix),\
(image_center[0]+height_laser_pix, image_center[1]-width_laser_pix)))
print(coord_laser)
print(self.new_coord_laser)
print(image_center)
#rectification
self.current_image = rectif(current_image, coord_laser, self.new_coord_laser) |
Partager