Ask Your Question
0

estimateRigidTransform Error in OpenCV4

asked 2020-02-22 14:50:47 -0600

Hi, Following python code was working in older version of cv but due to deprecation of estimateRigidTransform function in cv4, it is not working. So, I replaced estimateRigidTransform with estimateAffine2D to make it functional in opencv4.

    target_pts = np.array([[tx1, ty1], [tx2, ty2], [tx3, ty3], [tx4, ty4]]).astype(np.float32) * scale
    org_pts = np.array([[x1, y1], [x2, y2], [x3, y3], [x4, y4]]).astype(np.float32)
    #mat_ = cv2.estimateRigidTransform(org_pts, target_pts, True)
    mat_ = cv2.estimateAffine2D(org_pts, target_pts)
    dsize = (int(120 * scale), int(48 * scale))
    warped = cv2.warpAffine(image, mat_, dsize)

The above code is now throwing error TypeError: Expected Ptr<cv::umat> for argument 'M' for last line warpAffine function params due to change in argument value (I think).

Please guide, How I can replace estimateRigidTransform with other to make it functional. What steps should I do

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-02-22 14:58:57 -0600

LBerger gravatar image

updated 2020-02-22 22:24:38 -0600

Try warped = cv2.warpAffine(image[:,:,0], mat_[0], dsize)

estimateAffine2D return two values -> read doc no error with this code windows 64 bits and '4.2.0-dev'

import numpy as np
import cv2


image = cv2.imread('g:/lib/opencv/samples/data/lena.jpg')
if image is None:
    print("error")
tx1,ty1=100,100
tx2,ty2=100,200
tx3,ty3=200,200
tx4,ty4=200,100
scale = 1
x1,y1=100,100
x2,y2=100,200
x3,y3=200,200
x4,y4=200,100

target_pts = np.array([[tx1, ty1], [tx2, ty2], [tx3, ty3], [tx4, ty4]]).astype(np.float32) * scale
org_pts = np.array([[x1, y1], [x2, y2], [x3, y3], [x4, y4]]).astype(np.float32)
mat_,inlier = cv2.estimateAffine2D(org_pts, target_pts)
dsize = (int(120 * scale), int(48 * scale))
warped = cv2.warpAffine(image, mat_, dsize)
edit flag offensive delete link more

Comments

Error while reading warped.shape

ValueError: not enough values to unpack (expected 3, got 2)

Zohaib Niaz gravatar imageZohaib Niaz ( 2020-02-22 15:12:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-22 14:49:12 -0600

Seen: 4,581 times

Last updated: Feb 22 '20