def deflectomotery(objectName, imgDir):

    Img = Image(imgDir, objectName)

    Gradient_V = setGrad(Img.imgVSet, 3.8)
    Gradient_H = setGrad(Img.imgHSet, 3.8)

    #cv2.imwrite(os.path.join(imgDir, 'GradV.png'), np.array(Gradient_V * 255, dtype=np.uint8))
    #cv2.imwrite(os.path.join(imgDir, 'GradH.png'), np.array(Gradient_H * 255, dtype=np.uint8))

    N = np.zeros((Img.height, Img.width, 3), dtype=Img.PRECISION_IMG)
    N[..., 0] = -Gradient_V / np.sqrt(np.square(Gradient_V) + np.square(Gradient_H) + 1)
    N[..., 1] = -Gradient_H / np.sqrt(np.square(Gradient_V) + np.square(Gradient_H) + 1)
    N[..., 2] = 1 / np.sqrt(np.square(Gradient_V) + np.square(Gradient_H) + 1)

    # crop valid region
    Ncrop = N[Img.mask[0]:Img.mask[2], Img.mask[1]:Img.mask[3]]
    A = Img.A[Img.mask[0]:Img.mask[2], Img.mask[1]:Img.mask[3]]

    [newHeight, newWidth, _] = A.shape

    Nfname = os.path.join(imgDir, 'normal.png')
    # xyz to zyx because of OPENCV BGR order
    cv2.imwrite(Nfname, cv2.cvtColor(np.array((Ncrop + 1) / 2.0 * 255, dtype=np.uint8), cv2.COLOR_RGB2BGR))

    mesh = Mesh(objectName, newHeight, newWidth, Img.mask)
    mesh.setNormal(N)
    mesh.setDepth()
    mesh.setTexture(A)
    mesh.exportOBJ(imgDir, True)