回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一张扭曲的图片,a点、B点、C点和D点不失真地形成一个1厘米×1厘米的正方形。在</p>
<p><a href="https://i.stack.imgur.com/AhnCj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AhnCj.jpg" alt="enter image description here"/></a></p>
<p>我试着用单纯形法来纠正它,但是它扭曲了AD和BC这两条线,你可以在图中看到。在</p>
<p><a href="https://i.stack.imgur.com/LSC2W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LSC2W.png" alt="enter image description here"/></a></p>
<p>你知道我该怎么纠正吗?在</p>
<p>非常感谢!在</p>
<p>玛丽-编码器初学者</p>
<p>注:为了提供信息,图像是在一个有大视场的内窥镜摄像机的管子里拍摄的,这样可以在摄像机周围拍摄到管子的照片。我将使用1*1厘米的正方形来估计根的生长,并随时间推移拍摄几张照片。在</p>
<p>这是我的代码:</p>
<pre><code>import cv2
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__' :
# Read source image.
im_src = cv2.imread('points2.jpg', cv2.IMREAD_COLOR)
# Four points of the miniR image
pts_src = np.array([[742,223],[806,255],[818,507],[753,517]], dtype=float)
# Read destination image.
im_dst = cv2.imread('rectangle.jpg', cv2.IMREAD_COLOR)
# Four points of the square
pts_dst = np.array([[200,200],[1000,200],[1000,1000],[200,1000]], dtype=float)
# Calculate Homography
h, status = cv2.findHomography(pts_src, pts_dst)
# Warp source image to destination based on homography
im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))
cv2.imwrite('corrected2.jpg', im_out)
# Display images
cv2.imshow("Source Image", im_src)
cv2.imshow("Destination Image", im_dst)
cv2.imshow("Warped Source Image", im_out)
cv2.waitKey(0)
</code></pre>