I'm new to Python, therefore having troubles with debugging a script. I'm trying to create an ' average face ' using an opencv
script to recreate with my own images. Here's the Github repo I'm using, but same goes for this one and this one .
The land mark detection part works but the average.py
script throws the error I don't understand how to solve.
The first two errors I solved by replacing the xrange()
function with range()
. Than the estimateRigidTransform()
seemed depricated and there for I swapped it with estimateAffinePartial2D()
so far so good.
Now the console throws me the following error:
TypeError: Expected cv::UMat for argument 'M'
This is the scripts' code snippet:
# Apply affine transform calculated using src_tri and dst_tri to src and
# output an image of size.
def apply_affine_transform(src, src_tri, dst_tri, size):
# Given a pair of triangles, find the affine transform.
warp_mat = cv2.getAffineTransform(np.float32(src_tri), np.float32(dst_tri))
# Apply the Affine Transform just found to the src image
dst = cv2.warpAffine(src, warp_mat, (size[0], size[1]), None,
flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
return dst
For more reproducible code see repos in introduction of this question.
All help much appreciated!
Instead of using tform = cv2.estimateAffinePartial2D(np.array([inPts]), np.array([outPts]))
and returning tform
, return tform[0]
.
Refer to the documentation for more details.
You will notice that estimateAffinePartial2D
returns retVal
and inliers
. That's why when you are returning tform
, you are getting a TypeError
.
I have also created a PR to fix the code on our LearnOpenCV GitHub repository.
Vishwesh
Edit : You can check the PR here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.