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

  • Home
  • SEARCH
  • 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 8783353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:48:41+00:00 2026-06-13T20:48:41+00:00

I have 2 test images here. My is question is, how to map the

  • 0

I have 2 test images here. My is question is, how to map the square in first image to the quadrilateral in the second image without cropping the image.

Image 1:
image 1

Image 2:
image 2

Here is my current code using openCV warpPerspective function.

import cv2
import numpy as np

img1_square_corners = np.float32([[253,211], [563,211], [563,519],[253,519]])
img2_quad_corners = np.float32([[234,197], [520,169], [715,483], [81,472]])

h, mask = cv2.findHomography(img1_square_corners, img2_quad_corners)
im = cv2.imread("image1.png")
out = cv2.warpPerspective(im, h, (800,800))
cv2.imwrite("result.png", out)

Result:
result

As you can see, because of dsize=(800,800) parameter in the warpPerspective function, I can’t get full view of image 1. If I adjust the dsize, the square won’t map properly. Is there any way to resize the output image so that I can get whole picture of image 1?

  • 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-13T20:48:43+00:00Added an answer on June 13, 2026 at 8:48 pm

    Yes, but you should realise that the output image might be very large. I quickly wrote the following Python code, but even a 3000 x 3000 image could not fit the output, it is just way too big due to the transformation. Although, here is my code, I hope it will be of use to you.

    import cv2
    import numpy as np
    import cv           #the old cv interface
    
    img1_square_corners = np.float32([[253,211], [563,211], [563,519],[253,519]])
    img2_quad_corners = np.float32([[234,197], [520,169], [715,483], [81,472]])
    
    h, mask = cv2.findHomography(img1_square_corners, img2_quad_corners)
    im = cv2.imread("image1.png")
    

    Create an output image here, I used (3000, 3000) as an example.

    out_2 = cv.fromarray(np.zeros((3000,3000,3),np.uint8))
    

    By using the old cv interface, I wrote directly to the output, and so it does not get cropped. I tried this using the cv2 interface, but for some reason it did not work… Maybe someone can shed some light on that?

    cv.WarpPerspective(cv.fromarray(im), out_2, cv.fromarray(h))
    cv.ShowImage("test", out_2)
    cv.SaveImage("result.png", out_2)
    cv2.waitKey()
    

    Anyway, this gives a very large image, that contains your original image 1, warped. The entire image will be visible if you specify the output image to be large enough. (Which might be very large indeed!)

    I hope that this code may help you.

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

Sidebar

Related Questions

Here is my page: http://budclarychevy.com/custom/parts-specials-test My aim is to have the images clickable and
Good day, I have like 2 question here: First a background information. from the
I have the following HTML: Current HTML <div id=testContainer> <a href=testPage.htm target=_top> <img src=/res/images/testImage_M.jpg?lc=en-GB&lv=5.jpg
I have a quick question. I want to change the images of GridView if
I have to find the next image, based on the current image path. It's
I have actually seen this question quite a bit here, but none of them
I have a question about how to deploy WPF application into a PC without
First question on S.O. I have to do a search result page in asp.net
This is my fourth question here in about two weeks... I think I have
I have a code in VC2010 which I've reduced to a small example. Test.h:

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.