Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:55:28+00:00 2026-06-17T11:55:28+00:00

I am trying to rectify an image using a perspective warp in OpenCV and

  • 0

I am trying to rectify an image using a perspective warp in OpenCV and Python. I know the orientation of the camera (X, Y, Z angles) in reference the plane that needs warping. I know that the easiest method is to compute a homography matrix based on known points, however I am trying to do the same thing when that information is not available. The code which I am working with creates a rotational matrix then combines the translational and intrinsic matrices. Currently the code only works with manipulations to the z axis. Any manipulation of the x and y axis results in weird distortion of the image. I am basing my code off the answer at the bottom of the following post: Perspective Warping in OpenCV based on know camera orientation

Attached is the original image and a warped image from the standard homography method.

Original ImagePerspective Warp

from numpy import *
import cv

x = float(0)
y = float(5)
z = float(0)
f = 1

im = cv.LoadImage("Homography_test.jpg")
cv.NamedWindow("Distorted")
cv.NamedWindow("undistorted")

h, w = cv.GetSize(im)

x1 = x * (pi / 180)
y1 = y * (pi / 180)
z1 = z * (pi / 180)

# Create a rotation matrix
R_array = array([[x1], [y1], [z1]])
R_Vec = cv.fromarray(R_array)
R = cv.CreateMat(3, 3, cv.CV_64FC1)

cv.Rodrigues2(R_Vec, R)

#Create and combine with translation matrix
Trans_Mat = array([[[1], [0], [-w/2]],
                    [[0], [1], [-h/2]],
                    [[0], [0], [1]]])

Trans_Mat2 = cv.fromarray(Trans_Mat)
R_T_Mat = dot(R, Trans_Mat2)

#Create and combine with camera matrix
Intrinsic_Mat = array([[[f], [0], [w/2]],
                       [[0], [f], [h/2]],
                       [[0], [0], [1]]])

Int_Mat = cv.fromarray(Intrinsic_Mat)
H = dot(Int_Mat, R_T_Mat)
H2 = cv.fromarray(H)

persp = cv.CreateImage(cv.GetSize(im), cv.IPL_DEPTH_8U, 3)
cv.WarpPerspective(im, persp, H2)

cv.ShowImage("Distorted", im)
cv.ShowImage("undistorted", persp)

cv.WaitKey(0)
cv.DestroyWindow("Distorted")
cv.DestroyWindow("undistorted")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:55:29+00:00Added an answer on June 17, 2026 at 11:55 am

    you seem to be missing step 4 from my solution which was “move the image down the z axis” the line I used to do that was.

    //4
    trans(2,2) += image.rows;
    

    I chose image.rows arbitrarily, it gave a good sense of scale to the rotation I used in the example. Since you are not doing that your z coord is fixed at 1. I would imagine that is the cause of the distortion when you rotate around x and y, essentially since the image is so close to the camera when it rotates around x or y the perspective distortion is massive. The larger the translation down the z axis the smaller the distortion should appear. If you don’t want the image to shrink as it moves down the z axis, just increase your focal length as well. You might notice in my example I set my focal length to be image.rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rectify a previous database creation with tables that contains data
Hi I am using ios5 twitter integration, I know that one unique message will
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
i am trying to create a new flash movie. i am using CS4, for
I have a fairly complex relationship that I am trying to make work with
I am trying to create a homescreen widget using the 3.1 SDK. I followed
My datagrid has two textbox columns and two button column. I was trying that
I've made a pathfinding visualizer using python and pygame. As of now, it can
I am building an application in Java using Netbeans IDE. I am trying to
I have come across a problem that I don't know how to resolve involving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.