这个问题是关于OpenCV的功能findHomography,getPerspectiveTransform&getAffineTransform
有什么区别findHomography和getPerspectiveTransform?我从文档中理解的是,getPerspectiveTransform使用4个对应关系(这是计算单应性/透视变换所需的最小值)findHomography计算变换,即使你提供4个以上的对应关系(大概使用像最小二乘法这样的东西),计算变换也是如此? ).它是否正确?(在这种情况下,OpenCV仍然继续支持getPerspectiveTransform的唯一原因应该是遗留?)
我的下一个问题是,我想知道是否有相当于findHomography计算仿射变换的东西?即使用最小二乘法或等效鲁棒方法计算和仿射变换的函数.根据文档getAffineTransform只需3个对应关系(这是计算仿射变换所需的最小值).
最好,
我目前正在使用 opencv (CV2) 和 Python Pillow 图像库来尝试拍摄任意手机的图像并用新图像替换屏幕。我已经到了可以拍摄图像并识别手机屏幕并获得角落的所有坐标的地步,但是我很难用新图像替换图像中的那个区域。
我到目前为止的代码:
import cv2
from PIL import Image
image = cv2.imread('mockup.png')
edged_image = cv2.Canny(image, 30, 200)
(contours, _) = cv2.findContours(edged_image.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key = cv2.contourArea, reverse = True)[:10]
screenCnt = None
for contour in contours:
peri = cv2.arcLength(contour, True)
approx = cv2.approxPolyDP(contour, 0.02 * peri, True)
# if our approximated contour has four points, then
# we can assume that we have found our screen
if len(approx) == 4:
screenCnt = …Run Code Online (Sandbox Code Playgroud)